oauth2

package
v0.0.0-...-c9838ac Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2016 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FinishAuthorizeRequest

func FinishAuthorizeRequest(serviceName, code string) (*models.User, error)

FinishAuthorizeRequest validates code value and tries to find user.

func HandleAuthorizeRequest

func HandleAuthorizeRequest(serviceName string) string

HandleAuthorizeRequest generates authorization URL for specified service.

func HandleService

func HandleService(serviceName string) error

HandleService validates that service name is valid and allowed.

func Init

func Init()

Init initializes oauth2 module.

func ValidateAuthorizeRequest

func ValidateAuthorizeRequest(serviceName, state string) error

ValidateAuthorizeRequest validates that state value is valid.

Types

type Config

type Config struct {
	ClientID     string
	ClientSecret string
	RedirectURL  string
	Scopes       []string

	Endpoint Endpoint
}

Config describes a typical 3-legged OAuth2 flow, with both the client application information and the server's endpoint URLs.

func NewGitHub

func NewGitHub(clientID, clientSecret, redirectURL string,
	scopes []string) *Config

NewGitHub initializes new config for GitHub service.

func (*Config) AuthCodeURL

func (c *Config) AuthCodeURL(state string) string

AuthCodeURL constructs authorization url according to the config.

func (*Config) Exchange

func (c *Config) Exchange(code string) (*Token, error)

Exchange exchanges authorization code to the access token.

func (*Config) User

func (c *Config) User(token *Token) (*User, error)

User returns the user's data from authorization service.

type Endpoint

type Endpoint struct {
	AuthURL  string
	TokenURL string
	UserURL  string
}

Endpoint contains the OAuth 2.0 provider's authorization, token and user endpoint URLs.

type Token

type Token struct {
	Access string
	Type   string
	Scopes []string
}

Token represents the crendentials used to authorize the requests to access protected resources on the OAuth 2.0 provider's backend.

type User

type User struct {
	ID    int64
	Name  string
	Email string
}

User represents the user's data from authorization service.

Jump to

Keyboard shortcuts

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