# @schybo-quizzing/react-oauth-discord

> OAuth2 Enabled Button for Discord Login

Latest version **1.1.7** (published 2023-03-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install @schybo-quizzing/react-oauth-discord
pnpm add @schybo-quizzing/react-oauth-discord
yarn add @schybo-quizzing/react-oauth-discord
bun add @schybo-quizzing/react-oauth-discord
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.7 |
| Published | 2023-03-11 |
| First published | 2023-02-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 73.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Brent Scheibelhut |
| Maintainers | schybo-quizzing |
| Keywords | discord, react, oauth, login, reactjs, react-component, react-oauth-discord, react-discord-login, react-social-login, react-oauth, react-login, discord-login, discord-oAuth2, discord-oAuth |

## Links

- npm: https://www.npmjs.com/package/@schybo-quizzing/react-oauth-discord
- Repository: https://github.com/schybo/react-oauth-discord
- Homepage: https://github.com/schybo/react-oauth-discord#readme
- Issues: https://github.com/schybo/react-oauth-discord/issues
- npm.io page: https://npm.io/package/@schybo-quizzing/react-oauth-discord

## Dependencies (1)

- [@babel/polyfill](https://npm.io/package/@babel/polyfill.md) ^7.12.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.7 (latest) — 2023-03-11
- 1.1.6 — 2023-03-02
- 1.1.5 — 2023-02-28
- 1.1.4 — 2023-02-28
- 1.1.3 — 2023-02-27
- 1.1.2 — 2023-02-27
- 1.1.1 — 2023-02-27
- 1.1.0 — 2023-02-27
- 1.0.9 — 2023-02-26
- 1.0.8 — 2023-02-26
- 1.0.7 — 2023-02-26
- 1.0.6 — 2023-02-26
- 1.0.5 — 2023-02-26
- 1.0.4 — 2023-02-25
- 1.0.3 — 2023-02-25
- … 3 more at https://npm.io/package/@schybo-quizzing/react-oauth-discord/versions

## README

# react-oauth-discord

Discord OAuth2 React Button built for [**Schybo Quizzing**](https://schybo.com)

Sign users in automatically when they return to your site on any device or browser,
supports both the Authorization and Implicit flow

## Install

```sh
$ npm install @schybo-quizzing/react-oauth-discord@latest

# or

$ yarn add @schybo-quizzing/react-oauth-discord@latest
```

![button](https://schybo.com/images/discordButton.png)

## Demo & How to use to fetch user details

[Storybook](https://64007c7a93526a71257d3189--admirable-zabaione-6cec50.netlify.app/?path=/story/example-discordbutton--large&args=size:medium)

## User authorization for Discord APIs (with custom button)

OAuth 2.0 implicit and authorization code flows for web apps

> OAuth2 enables application developers to build applications that utilize authentication and data from the Discord API. Within Discord, there are multiple types of OAuth2 authentication. We support the authorization code grant, the implicit grant, client credentials, and some modified special-for-Discord flows for Bots and Webhooks.

## How to use

1. Get your [**Discord API client ID**](https://discord.com/developers/applications)

https://discord.com/developers/applications > Application > OAuth2

> Key Point: Add both `http://localhost` and `http://localhost:<port_number>` to the Authorized JavaScript origins box for local tests or development.

2. Import Discord Button

### Sign In With Google

```jsx
import { DiscordLogin } from '@schybo-quizzing/react-oauth-discord'

<DiscordLogin
  discordClientId={DISCORD_CLIENT_ID}
  redirectUri={DISCORD_REDIRECT_URI}
  debug={true}
  backgroundColor={backgroundColor}
  size={size}
  label={label}
  newTab={newTab}
  props={props}>
<DiscordLogin>
```

#### Implicit flow

```jsx
import { DiscordLogin } from '@schybo-quizzing/react-oauth-discord'

const login = () => {
  const params = new Proxy(new URLSearchParams(window.location.search), {
    get: (searchParams, prop) => searchParams.get(prop),
  });
  let value = params.code;
}

<DiscordLogin
  discordClientId={DISCORD_CLIENT_ID}
  redirectUri={DISCORD_REDIRECT_URI}
  debug={true}
  backgroundColor={backgroundColor}
  size={size}
  label={label}
  newTab={newTab}
  props={props}
  onclick={login}>
<DiscordLogin>
```

## API

| Required | Prop            | Type                           | Description                                                                                                  |
| :------: | --------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------ |
|    ✓     | discordClientId | `string`                       | Your Discord Client Id. Find yours at: https://discord.com/developers/applications > Application > OAuth2    |
|    ✓     | redirectUri     | `function`                     | redirect Url after oAuth success or failure. See below for more information                                  |
|          | debug           | `boolean`                      | Provides helpful console debugging statements                                                                |
|          | backgroundColor | `string`                       | Background color of button                                                                                   |
|          | size            | `large` \| `medium` \| `small` | Button [size](https://developers.google.com/identity/gsi/web/reference/js-reference#size)                    |
|          | label           | `string`                       | Button contents. Default: `Sign in with Discord`                                                             |
|          | scopes          | `[string]`                     | String array of scopes you need access to. Default: `['identify', 'email']`. See below for more information. |
|          | responseType    | `string`                       | Response type wanted from Discord oAuth. Default: `code`                                                     |
|          | newTab          | `boolean`                      | Whether to open the oAuth box in a new tab                                                                   |
|          | onclick         | `function`                     | Optional click handler                                                                                       |
|          | buttonClasses   | `string`                       | Optional extra classes to apply to the button                                                                |
|          | props           | `JSON`                         | Optional extra props                                                                                         |
|          |

## redirectUri

URL to redirect too after success or failure of user auth. Will attach discord code to be used in follow up api requests as the query parameter `code`. Has to match one of the URLs under https://discord.com/developers/applications > Application > OAuth2. If doing server auth Authorization flow, redirect to your server endpoint handling the rest of the login. Otherwise you can redirect to your and handle there

## scopes

String array of scopes you need access to. Identify should always be applied, and if you're doing the Authorization flow you'll probably need `identify` as well. Default is ['identify', 'email']

---
_Source: https://npm.io/package/@schybo-quizzing/react-oauth-discord · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
