discord

package module
v0.0.0-...-3449fc8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2021 License: MIT Imports: 1 Imported by: 0

README

Discord OAuth 2.0

This is a provider for the package golang.org/x/oauth2 implementing authentication endpoints for Discord

Install

$ go get github.com/ravener/discord-oauth2

Usage

package main

import (
  "github.com/pollen5/discord-oauth2"
  "golang.org/x/oauth2"
)

func main() {
  conf := &oauth2.Config{
    Endpoint: discord.Endpoint,
    Scopes: []string{discord.ScopeIdentify},
    RedirectURL: "http://localhost:3000/auth/callback",
    ClientID: "id",
    ClientSecret: "secret",
  }
  // Use oauth2 package as normal, i.e
  // redirect users to conf.AuthCodeURL("state") for initial auth
  // then inside the callback:
  //  - verify the state param as needed.
  //  - exchange code with conf.Exchange(oauth2.NoContext, code)
  //  - Store in session if necessary, etc.
  // to get like user's info use conf.Client(ctx, token) to get a proper http client
  // for such requests.
}

A full authentication flow example server can be found in example directory

License

MIT

Documentation

Index

Constants

View Source
const (
	ScopeIdentify                   = "identify"
	ScopeBot                        = "bot"
	ScopeEmail                      = "email"
	ScopeGuilds                     = "guilds"
	ScopeGuildsJoin                 = "guilds.join"
	ScopeConnections                = "connections"
	ScopeGroupDMJoin                = "gdm.join"
	ScopeMessagesRead               = "messages.read"
	ScopeRPC                        = "rpc"                    // Whitelist only
	ScopeRPCAPI                     = "rpc.api"                // Whitelist only
	ScopeRPCNotificationsRead       = "rpc.notifications.read" // Whitelist only
	ScopeWebhookIncoming            = "webhook.Incoming"
	ScopeApplicationsBuildsUpload   = "applications.builds.upload" // Whitelist only
	ScopeApplicationsBuildsRead     = "applications.builds.read"
	ScopeApplicationsStoreUpdate    = "applications.store.update"
	ScopeApplicationsEntitlements   = "applications.entitlements"
	ScopeRelationshipsRead          = "relationships.read" // Whitelist only
	ScopeActivitiesRead             = "activities.read"    // Whitelist only
	ScopeActivitiesWrite            = "activities.write"   // Whitelist only
	ScopeApplicationsCommands       = "applications.commands"
	ScopeApplicationsCommandsUpdate = "applications.commands.update"
)

All scope constants that can be used.

Variables

View Source
var Endpoint = oauth2.Endpoint{
	AuthURL:   "https://discordapp.com/api/oauth2/authorize",
	TokenURL:  "https://discordapp.com/api/oauth2/token",
	AuthStyle: oauth2.AuthStyleInParams,
}

Endpoint is Discord's OAuth 2.0 endpoint.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
Extremely barebones server to demonstrate OAuth 2.0 flow with Discord Uses native net/http to be dependency-less and easy to run.
Extremely barebones server to demonstrate OAuth 2.0 flow with Discord Uses native net/http to be dependency-less and easy to run.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL