oguth

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

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

Go to latest
Published: May 1, 2015 License: MIT Imports: 7 Imported by: 0

README

oguth

GoDoc

Description

oguth is a OAuth2 authorization server library. WIP now. Code will broke.

Install

$ go get github.com/aoisensi/oguth

Licence

MIT

Author

aoisensi

Documentation

Index

Constants

View Source
const (
	GrantRefreshToken      GrantType = "refresh_token"
	GrantAuthCode                    = "authorization_code"
	GrantPassword                    = "password"
	GrantClientCredentials           = "client_credentials"
)
View Source
const (
	ErrorCodeInvalidRequest          ErrorCode = "invalid_request"
	ErrorCodeUnauthorizedClient                = "unauthorized_client"
	ErrorCodeUnsupportedGrantType              = "unsupported_grant_type"
	ErrorCodeUnsupportedResponseType           = "unsupported_response_type"
	ErrorCodeAccessDenied                      = "access_denied"
	ErrorCodeInvalidScope                      = "invalid_scope"
	ErrorCodeServerError                       = "server_error"
	ErrorCodeTemporarilyUnavailable            = "temporarily_unavailable"
)

Variables

View Source
var (
	ErrorGrantTypeMissing = &Error{
		Error:            ErrorCodeInvalidRequest,
		ErrorDescription: "Required parameter is missing: grant_type",
	}
	ErrorResponseTypeMissing = &Error{
		Error:            ErrorCodeInvalidRequest,
		ErrorDescription: "Required parameter is missing: response_type",
	}
	ErrorClientIdMissing = &Error{
		Error:            ErrorCodeInvalidRequest,
		ErrorDescription: "Required parameter is missing: client_id",
	}
	ErrorUnavailableScope = &Error{
		Error:            ErrorCodeInvalidScope,
		ErrorDescription: "Unknown scope(s) have been included in the request",
	}
	ErrorUnsupportedGrantType = &Error{
		Error:            ErrorCodeUnsupportedGrantType,
		ErrorDescription: "This grant type is not supported",
	}
	ErrorUnsupportedResponseType = &Error{
		Error:            ErrorCodeUnsupportedResponseType,
		ErrorDescription: "The authorization server does not support obtaining an authorization code using this method",
	}
	ErrorClientNotFound = &Error{
		Error:            ErrorCodeInvalidRequest,
		ErrorDescription: "The OAuth client was not found.",
	}
	ErrorRefreshTokenInvalid = &Error{
		Error:            ErrorCodeInvalidRequest,
		ErrorDescription: "The refresh token is invalid.",
	}
)
View Source
var DefaultConfig = NewConfig()

Functions

func DefaultAccessTokenGenerator

func DefaultAccessTokenGenerator() (code string)

func DefaultAuthCodeGenerator

func DefaultAuthCodeGenerator() (code string)

func DefaultRefreshTokenGenerator

func DefaultRefreshTokenGenerator() (code string)

func SimpleRandomTokenGenerator

func SimpleRandomTokenGenerator(size int) string

Types

type AccessHandler

type AccessHandler func(*OAuth, *http.Request) (interface{}, int)

type AccessHandlers

type AccessHandlers map[GrantType]AccessHandler

type AccessToken

type AccessToken interface {
	GetClient() Client
	GetExpires() time.Time
}

type AuthHandler

type AuthHandler func(*OAuth, http.ResponseWriter, *http.Request)

type AuthHandlers

type AuthHandlers map[ResponseType]AuthHandler

type Authorize

type Authorize interface {
	GetClientId() string
	GetExpires() time.Time
	GetRedirectUri() string
	SetClient(Client)
	GetClient() Client
}

type Client

type Client interface {
}

type Config

type Config struct {
	Storage Storage
	Owner   ResourceOwner

	AuthorizeExpires time.Duration

	AccessTokenExpires time.Duration

	AuthorizeGenerator    func() string
	AccessTokenGenerator  func() string
	RefreshTokenGenerator func() string

	AuthorizeEndpoint   string
	AccessTokenEndpoint string
	RedirectEndpoint    string
	AuthHandlers        AuthHandlers
	AccessHandlers      AccessHandlers
	TokenType           TokenType

	AvailableScopes Scopes
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig() Config

type Error

type Error struct {
	Error            ErrorCode `json:"error"`
	ErrorDescription string    `json:"error_description"`
	ErrorUri         string    `json:"error_uri"`
	State            string    `json:"state"`
}

func NewError

func NewError(code ErrorCode) *Error

func (*Error) ToValues

func (e *Error) ToValues() url.Values

func (*Error) Write

func (e *Error) Write(w http.ResponseWriter)

type ErrorCode

type ErrorCode string

type GrantType

type GrantType string

type OAuth

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

func NewOAuth

func NewOAuth(config Config) *OAuth

func (*OAuth) AccessTokenRequestHandler

func (a *OAuth) AccessTokenRequestHandler(w http.ResponseWriter, r *http.Request)

func (*OAuth) AuthorizeRequestHandler

func (a *OAuth) AuthorizeRequestHandler(w http.ResponseWriter, r *http.Request)

func (*OAuth) Close

func (a *OAuth) Close()

func (*OAuth) ConnectClientToCode

func (a *OAuth) ConnectClientToCode(code string, client Client) error

func (*OAuth) RedirectAuthorize

func (a *OAuth) RedirectAuthorize(w http.ResponseWriter, r *http.Request, v url.Values)

func (*OAuth) VerifyAccess

func (a *OAuth) VerifyAccess(w http.ResponseWriter, r *http.Request) (Client, error)

type RefreshToken

type RefreshToken interface {
	GetClient() Client
}

type ResourceOwner

type ResourceOwner interface {
	ExistClientId(id string) bool
	GetClient(id, secret string) Client
	GetClientWithPasswordGrant(username, password string) Client
	GetRedirectUri(clientId string) string
	Close()
	AuthCodeDecision(r *http.Request, clientId string) Client
	AuthCodeMissing(w http.ResponseWriter, r *http.Request)
}

type ResponseType

type ResponseType string
const (
	ResponseCode  ResponseType = "code"
	ResponseToken              = "token"
)

type Scopes

type Scopes []string

func ParseScopes

func ParseScopes(s string) Scopes

func (Scopes) Available

func (s Scopes) Available(oauth *OAuth) *Error

func (Scopes) ContainScope

func (scopes Scopes) ContainScope(scope string) bool

func (Scopes) ContainScopes

func (root Scopes) ContainScopes(scopes Scopes) bool

type Storage

type Storage interface {
	AddAuthorize(code string, auth Authorize)
	GetAuthorize(code string) Authorize
	DisableAuthorize(id string)

	AddAccessToken(token string, access AccessToken)
	GetAccessToken(token string) AccessToken

	AddRefreshToken(token string, refresh RefreshToken)
	GetRefreshToken(token string) RefreshToken
	DisableRefreshToken(token string)
}

func NewMemoryStorage

func NewMemoryStorage() Storage

type TokenType

type TokenType string
const (
	TokenTypeBearer TokenType = "Bearer"
	TokenTypeMAC              = "MAC"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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