oauth2

package
v0.0.0-...-61fa54b Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2013 License: MIT, MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// grant_type for requesting a refresh_token
	GrantTypeRefreshToken = "refresh_token"

	// grant_type for requesting an access_token using an
	// authorization code.
	GrantTypeAuthorizationCode = "authorization_code"

	// grant_type for requesting access to resources owned by the
	// registered application (client).
	GrantTypeClientCredentials = "client_credentials"

	// grant_type for exchanging a username and password for
	// an access_token
	GrantTypePassword = "password"
)

Enumerates authorization grants (grant_type) used by the client to obtain an access token.

View Source
const (
	// response_type for requesting an authoriztion code
	ResponseTypeCode = "code"

	// response_type for requesting or refreshing an access_token
	ResponseTypeToken = "token"
)
View Source
const (
	TokenBearer = "bearer"
	TokenMac    = "mac"
)
View Source
const (
	// The request is missing a required parameter, includes an
	// unsupported parameter value (other than grant type), repeats
	// a parameter, includes multiple credentials, utilizes more than
	// one mechanism for authenticating the client, or is otherwise
	// malformed.
	ErrorCodeInvalidRequest = "invalid_request"

	// Client authentication failed (e.g. unknown client, no client
	// authentication included, or unsupported authentication method).
	ErrorCodeInvalidClient = "invalid_client"

	// The provided authorization grant (e.g. authorization
	// code, resource owner credentials) or refresh token is
	// invalid, expired, revoked, does not match the redirection
	// URI used in the authorization request, or was issued to
	// another client.
	ErrorCodeInvalidGrant = "invalid_grant"

	// The authenticated client is not authorized to use this
	// authorization grant type.
	ErrorCodeUnauthorizedClient = "unauthorized_client"

	// The authorization grant type is not supported by the
	// authorization server.
	ErrorCodeUnsupportedGrantType = "unsupported_grant_type"

	// The requested scope is invalid, unknown, malformed, or
	// exceeds the scope granted by the resource owner.
	ErrorCodeInvalidScope = "invalid_scope"
)

Enumerates ASCII [USASCII] error code returned by the OAuth2.0 Error Response.

View Source
const OOB = "urn:ietf:wg:oauth:2.0:oob"

Out-Of-Band mode, used for applications that do not have a callback URL, such as mobile phones or command-line utilities.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// The client_identifier issued to the client during the
	// registration process.
	ClientId string

	// The client_secret issued to the client during the
	// registration process.
	ClientSecret string

	// Used by the authorization server to return authorization credentials
	// responses to the client via the resource owner user-agent
	RedirectURL string

	// Used by the client to exchange an authorization grant for
	// an access token, typically with client authentication.
	AccessTokenURL string

	// Used by the client to obtain authorization from the resource
	// owner via user-agent redirection.
	AuthorizationURL string
}

Client represents an application making protected resource requests on behalf of the resource owner and with its authorization.

func (*Client) AuthorizeRedirect

func (c *Client) AuthorizeRedirect(scope, state string) string

AuthorizeRedirect constructs the Authorization Endpoint, where the user can authorize the client to access protected resources.

func (*Client) GrantToken

func (c *Client) GrantToken(code string) (*Token, error)

GrantToken will attempt to grant an Access Token using the specified authorization code.

func (*Client) GrantTokenCredentials

func (c *Client) GrantTokenCredentials(scope string) (*Token, error)

GrantTokenCredentials will attempt to grant an Access Token for the Client to access protected resources the the Client owns.

See http://tools.ietf.org/html/draft-ietf-oauth-v2-31#section-4.3

func (*Client) GrantTokenPassword

func (c *Client) GrantTokenPassword(username, password, scope string) (*Token, error)

GrantTokenPassword will attempt to grant an Access Token using the resource owner's credentials (username and password). The scope of the access request may be optinally included, or left empty.

See http://tools.ietf.org/html/draft-ietf-oauth-v2-31#section-4.3

func (*Client) RefreshToken

func (c *Client) RefreshToken(refreshToken string) (*Token, error)

RefreshToken requests a new access token by authenticating with the authorization server and presenting the refresh token.

type Error

type Error struct {
	// A single ASCII [USASCII] error code
	Code string `json:"error"`

	// A human-readable ASCII [USASCII] text providing
	// additional information, used to assist the client developer in
	// understanding the error that occurred.
	Description string `json:"error_description"`

	// A URI identifying a human-readable web page with
	// information about the error, used to provide the client
	// developer with additional information about the error.
	URI string `json:"error_uri"`
}

Error represents a failed request to the OAuth2.0 Authorization or Resource server.

func (Error) Error

func (e Error) Error() string

Error returns a string representation of the OAuth2 error message.

type Token

type Token struct {
	// The access token issued by the authorization server.
	AccessToken string `json:"access_token"`

	// The type of the token issued (bearer, mac, etc)
	TokenType string `json:"token_type"`

	// The refresh token, which can be used to obtain new
	// access tokens using the same authorization grant
	RefreshToken string `json:"refresh_token"`

	// The lifetime in seconds of the access token.  For
	// example, the value "3600" denotes that the access token will
	// expire in one hour from the time the response was generated.
	ExpiresIn int64 `json:"expires_in"`

	// The scope of the access token.
	Scope string
}

Token represents a successful response to an OAuth2.0 Access Token Request, including a Refresh Token request.

func (Token) Token

func (t Token) Token() string

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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