1.1.7 • Published 1 year ago

@schybo-quizzing/react-oauth-discord v1.1.7

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

react-oauth-discord

Discord OAuth2 React Button built for Schybo Quizzing

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

Install

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

# or

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

button

Demo & How to use to fetch user details

Storybook

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 > Application > OAuth2

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

  1. Import Discord Button

Sign In With Google

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

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

RequiredPropTypeDescription
discordClientIdstringYour Discord Client Id. Find yours at: https://discord.com/developers/applications > Application > OAuth2
redirectUrifunctionredirect Url after oAuth success or failure. See below for more information
debugbooleanProvides helpful console debugging statements
backgroundColorstringBackground color of button
sizelarge | medium | smallButton size
labelstringButton contents. Default: Sign in with Discord
scopes[string]String array of scopes you need access to. Default: ['identify', 'email']. See below for more information.
responseTypestringResponse type wanted from Discord oAuth. Default: code
newTabbooleanWhether to open the oAuth box in a new tab
onclickfunctionOptional click handler
buttonClassesstringOptional extra classes to apply to the button
propsJSONOptional 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'

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago