authcord

package module
v0.0.0-...-de1f37d Latest Latest
Warning

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

Go to latest
Published: May 11, 2019 License: BSD-3-Clause Imports: 8 Imported by: 0

README

authcord

A tiny Discord OAuth2 library that builds on x/oauth2 adding helper methods for Discord endpoints. Manages token refreshes, state and JSON decoding internally.

Usage

Refer to the examples.

Documentation

Overview

Package authcord is a tiny Discord OAuth2 library over x/oauth2

Index

Constants

View Source
const APIUrl = "http://discordapp.com/api/v6"

APIUrl is Discord's base API Url

Variables

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

Endpoint is Discord's OAuth2 endpoint

Functions

This section is empty.

Types

type Guild

type Guild struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Icon        string `json:"icon"`
	Owner       bool   `json:"owner"`
	Permissions uint   `json:"permissions"`
}

Guild is a partial Guild object

type Session

type Session struct {
	State string // a random 16 bit hex encoded string, to verify callback redirects
	// contains filtered or unexported fields
}

Session is the Discord session used to initialize the OAuth2 flow. All methods called on Session will internally refresh the access token if it is invalid

func New

func New(clientID, clientSecret, redirectURL string, scopes []string) *Session

New initializes a new session with the provided clientID, secret, redirect and scopes

func (*Session) AccessToken

func (s *Session) AccessToken() string

AccessToken fetches the internal access token

func (*Session) AuthURL

func (s *Session) AuthURL() string

AuthURL returns the authentication URL the end user can visit

func (*Session) Callback

func (s *Session) Callback(code string) error

Callback fetches an access token with the provided code and initializes an HTTP Client that can be used to do authenticated requests

func (*Session) Guilds

func (s *Session) Guilds() (g []*Guild, err error)

Guilds fetches a slice of partial guilds the user is a member of

func (*Session) User

func (s *Session) User() (u *User, err error)

User fetches the currently logged in user

type User

type User struct {
	ID            string `json:"id"`
	Username      string `json:"username"`
	Discriminator string `json:"discriminator"`
	Avatar        string `json:"avatar,omitempty"`
	Bot           bool   `json:"bot,omitempty"`
	MFAEnabled    bool   `json:"mfa_enabled,omitempty"`
	Locale        string `json:"locale,omitempty"`
	Verified      bool   `json:"verified,omitempty"`
	Email         string `json:"email,omitempty"` // only provided if email scope is passed
	Flags         uint   `json:"flags,omitempty"`
	PremiumType   uint8  `json:"premium_type,omitempty"`
}

User is a Discord user object as documented at https://discordapp.com/developers/docs/resources/user#user-object

Directories

Path Synopsis
A simple script to demo OAuth2 flow using authcord.
A simple script to demo OAuth2 flow using authcord.

Jump to

Keyboard shortcuts

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