oauth2

package
v0.0.0-...-4b6c822 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2017 License: MIT Imports: 10 Imported by: 32

README

OAuth2 package

Inspired by goauth2

Documentation

Index

Constants

View Source
const (
	OAuth2KeyClientID       string = "client_id"
	OAuth2KeySecret         string = "client_secret"
	OAuth2KeyRedirectUrl    string = "redirect_uri"
	OAuth2KeyScope          string = "scope"
	OAuth2KeyAccessType     string = "access_type"
	OAuth2KeyApprovalPrompt string = "approval_prompt"
	OAuth2KeyAuthURL        string = "auth_url"
	OAuth2KeyTokenURL       string = "token_url"
	OAuth2KeyCode           string = "code"
	OAuth2KeyGrantType      string = "grant_type"
	OAuth2KeyExpiresIn      string = "expires_in"
	OAuth2KeyAccessToken    string = "access_token"
	OAuth2KeyRefreshToken   string = "refresh_token"
	OAuth2KeyResponseType   string = "response_type"
)
View Source
const (

	// ApprovalPromptForce indicates that the user will always
	// have to reauthorize access if the AccessType is online.
	OAuth2ApprovalPromptForce string = "force"

	// ApprovalPromptAuto indicates that the user will not
	// have to reauthorize access.
	OAuth2ApprovalPromptAuto string = "auto"
)
View Source
const (

	// AccessTypeOnline indicates that the access type is online.
	OAuth2AccessTypeOnline string = "online"

	// AccessTypeOffline indicates that the access type is offline.
	OAuth2AccessTypeOffline string = "offline"
)
View Source
const (
	OAuth2GrantTypeAuthorizationCode = "authorization_code"
)

Variables

This section is empty.

Functions

func AuthorizationHeader

func AuthorizationHeader(creds *common.Credentials) (key, value string)

AuthorizationHeader returns the key, value pair to insert into an authorized request.

func CompleteAuth

func CompleteAuth(tripperFactory common.TripperFactory, data objx.Map, config *common.Config, provider common.Provider) (*common.Credentials, error)

CompleteAuth takes a map of arguments that are used to complete the authorisation process, completes it, and returns the appropriate common.Credentials.

The data must contain an OAuth2KeyCode obtained from the auth server.

func Get

func Get(provider common.Provider, creds *common.Credentials, endpoint string) (objx.Map, error)

Get executes an authenticated HTTP GET against the given provider and returns an objx.Map of the response.

The response type is automatically detected and used to unmarshal the response.

func GetBeginAuthURLWithBase

func GetBeginAuthURLWithBase(base string, state *common.State, config *common.Config) (string, error)

GetBeginAuthURLWithBase returns the OAuth2 authorization URL from the given arguments.

The state object will be encoded to base64 and signed to ensure integrity.

func GetClient

func GetClient(tripperFactory common.TripperFactory, creds *common.Credentials, provider common.Provider) (*http.Client, error)

GetClient gets an http.Client authenticated with the specified common.Credentials.

func MergeScopes

func MergeScopes(scopes ...string) string

func ParseScope

func ParseScope(scope string) string

Types

type OAuth2Tripper

type OAuth2Tripper struct {
	// contains filtered or unexported fields
}

func NewOAuth2Tripper

func NewOAuth2Tripper(creds *common.Credentials, provider common.Provider) *OAuth2Tripper

NewOAuth2Tripper creates a new OAuth2Tripper with the given arguments.

func (*OAuth2Tripper) Credentials

func (t *OAuth2Tripper) Credentials() *common.Credentials

Credentials returns the credentials associated with this OAuth2Tripper

func (*OAuth2Tripper) Provider

func (t *OAuth2Tripper) Provider() common.Provider

Provider returns the provider associated with this OAuth2Tripper

func (*OAuth2Tripper) RoundTrip

func (t *OAuth2Tripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip is called by the http package when making a request to a server. This implementation of RoundTrip inserts the appropriate authorization headers into the request in order to enable access of protected resources.

If the auth token has expired, RoundTrip will attempt to renew it.

type OAuth2TripperFactory

type OAuth2TripperFactory struct{}

OAuth2TripperFactory provides the NewTripper function that creates a Tripper object for the OAuth2 authentication protocol.

func (*OAuth2TripperFactory) NewTripper

func (f *OAuth2TripperFactory) NewTripper(creds *common.Credentials, provider common.Provider) (common.Tripper, error)

NewTripper creates a Tripper object for the OAuth2 authentication protocol.

Jump to

Keyboard shortcuts

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