oauth

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: MIT Imports: 7 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthData

type AuthData struct {
	ClientID     string `json:"client_id,omitempty"`
	ClientSecret string `json:"client_secret,omitempty"`
	Host         string `json:"host,omitempty"`
	// contains filtered or unexported fields
}

AuthData reflects the data common to 2-legged and 3-legged api calls

func (AuthData) GetHostPath added in v0.2.0

func (a AuthData) GetHostPath() string

GetHostPath returns host path, usually different in case of prd stg and dev environments

func (*AuthData) SetHostPath added in v0.2.0

func (a *AuthData) SetHostPath(host string)

SetHostPath allows changing the host, usually useful for switching between prd stg and dev environments

type Bearer

type Bearer struct {
	TokenType    string `json:"token_type"`              // Will always be Bearer
	ExpiresIn    int32  `json:"expires_in"`              // Access token expiration time (in seconds)
	AccessToken  string `json:"access_token"`            // The access token
	RefreshToken string `json:"refresh_token,omitempty"` // The refresh token used in 3-legged oauth
}

Bearer reflects the response when acquiring a 2-legged token or in 3-legged context for exchanging the authorization code for a token + refresh token and when exchanging the refresh token for a new token

type ForgeAuthenticator

type ForgeAuthenticator interface {
	GetToken(scope string) (Bearer, error)
	GetHostPath() string
	GetRefreshToken() string
}

ForgeAuthenticator defines an interface that allows abstraction of 2-legged and a 3-legged context.

This provides useful when an API accepts both 2-legged and 3-legged context tokens

type Information

type Information struct {
	Authenticator        ForgeAuthenticator
	InformationalAPIPath string
}

Information struct is holding the host and path used when making queries for profile of an authorizing end user in a 3-legged context

func NewInformationQuerier

func NewInformationQuerier(authenticator ForgeAuthenticator) Information

NewInformationQuerier returns an Informational API accessor with default host and profilePath

func (Information) AboutMe

func (i Information) AboutMe() (profile UserProfile, err error)

AboutMe is used to get the profile of an authorizing end user

type ThreeLeggedAuth

type ThreeLeggedAuth struct {
	AuthData
	RedirectURI  string
	RefreshToken string
}

ThreeLeggedAuth struct holds data necessary for making requests in 3-legged context

func NewThreeLegged added in v0.2.0

func NewThreeLegged(clientID, clientSecret, redirectURI, refreshToken string) *ThreeLeggedAuth

NewThreeLegged returns a 3-legged authenticator with default host and authPath, giving client secrets, redirectURI and optionally with a starting refresh token (useful for CLI apps)

func (ThreeLeggedAuth) Authorize

func (a ThreeLeggedAuth) Authorize(scope string, state string) (string, error)

Authorize method returns an URL to redirect an end user, where it will be asked to give his consent for app to access the specified resources.

The resources for which the permission is asked are specified as a space-separated list of required scopes. State can be used to specify, as URL-encoded payload, some arbitrary data that the authentication flow will pass back verbatim in a state query parameter to the callback URL.

Note: You do not call this URL directly in your server code.
See the Get a 3-Legged Token tutorial for more information on how to use this endpoint.

func (*ThreeLeggedAuth) ExchangeCode added in v0.2.0

func (a *ThreeLeggedAuth) ExchangeCode(code string) (bearer Bearer, err error)

ExchangeCode is used to exchange the authorization code for a token and an exchange token

func (ThreeLeggedAuth) GetNewRefreshToken added in v0.2.3

func (a ThreeLeggedAuth) GetNewRefreshToken(refreshToken string, scope string) (bearer Bearer, err error)

GetNewRefreshToken is used to get a new access token by using the refresh token provided by ExchangeCode

func (ThreeLeggedAuth) GetRefreshToken added in v0.2.4

func (a ThreeLeggedAuth) GetRefreshToken() string

func (*ThreeLeggedAuth) GetToken

func (a *ThreeLeggedAuth) GetToken(scope string) (token Bearer, err error)

func (*ThreeLeggedAuth) SetRefreshToken added in v0.2.0

func (a *ThreeLeggedAuth) SetRefreshToken(refreshtoken string)

type TwoLeggedAuth

type TwoLeggedAuth struct {
	AuthData
}

TwoLeggedAuth struct holds data necessary for making requests in 2-legged context

func NewTwoLegged added in v0.2.0

func NewTwoLegged(clientID, clientSecret string) *TwoLeggedAuth

NewTwoLegged returns a 2-legged authenticator with default host and authPath

func (TwoLeggedAuth) GetRefreshToken added in v0.2.4

func (a TwoLeggedAuth) GetRefreshToken() string

func (TwoLeggedAuth) GetToken added in v0.2.0

func (a TwoLeggedAuth) GetToken(scope string) (bearer Bearer, err error)

GetToken allows getting a token with a given scope

type UserProfile

type UserProfile struct {
	UserID    string `json:"userId"`    // The backend user ID of the profile
	UserName  string `json:"userName"`  // The username chosen by the user
	EmailID   string `json:"emailId"`   // The user’s email address
	FirstName string `json:"firstName"` // The user’s first name
	LastName  string `json:"lastName"`  // The user’s last name
	// true if the user’s email address has been verified false if the user’s email address has not been verified
	EmailVerified bool `json:"emailVerified"`
	// true if the user has enabled two-factor authentication false if the user has not enabled two-factor authentication
	Var2FaEnabled bool `json:"2FaEnabled"`
	// A flat JSON object of attribute-value pairs in which the attributes specify available profile image sizes in the
	// format sizeX<pixels> (where <pixels> is an integer that represents both height and width in pixels of square
	// profile images) and the values are URLs for downloading the images via HTTP
	ProfileImages interface{} `json:"profileImages"`
}

UserProfile reflects the response received when query the profile of an authorizing end user in a 3-legged context

Jump to

Keyboard shortcuts

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