services

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2020 License: AGPL-3.0 Imports: 3 Imported by: 6

README

go-oauth2-client

Mockable Go OAuth2 client for access a OAuth2 Server from a golang application

Installation

$ go get github.com/Ulbora/go-oauth2-client

Usage

Auth Code Grant Type

Auth Code Authorize
    var a AuthCodeAuthorize
    a.ClientID = "211"
    a.OauthHost = "http://localhost:3000"
    a.RedirectURI = "http:/localhost/token"
    a.Scope = "write"
    a.State = "12345"
    res := a.AuthCodeAuthorizeUser()
Auth Code Token
    var tn AuthCodeToken
    tn.OauthHost = "http://localhost:3000"
    tn.ClientID = "403"
    tn.Secret = "554444vfg55ggfff22454sw2fff2dsfd"
    tn.Code = "yfgk5mj481QSl46n2zIZGl"
    tn.RedirectURI = "http://www.google.com"
    token := tn.AuthCodeToken()

Auth Code Refresh
    var tn AuthCodeToken
    tn.OauthHost = "http://localhost:3000"
    tn.ClientID = "403"
    tn.Secret = "554444vfg55ggfff22454sw2fff2dsfd"
    tn.RefreshToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJjb2RlIiwidXNlcklkIjoia2VuIiwiY2xpZW50SWQiOjQwMywiaWF0IjoxNTAyNDE4NDQ1LCJ0b2tlblR5cGUiOiJyZWZyZXNoIiwiZXhwIjoxNTAyNDU0NDQ1LCJpc3MiOiJVbGJvcmEgT2F1dGgyIFNlcnZlciJ9.7rJPyXkVppTS_4_b3K8nUdnnrjmZI0R69_F7ii5_ueA"
    token := tn.AuthCodeRefreshToken()

Implicit Grant Type

Implicit Authorize
    var a ImplicitAuthorize
    a.ClientID = "403"
    a.OauthHost = "http://localhost:3000"
    a.RedirectURI = "http://www.google.com"
    a.Scope = "read"
    a.State = "12345"
    res := a.ImplicitAuthorize()

Client Credentials Grant Type

Client Credentials Token
    var tn ClientCredentialsToken
    tn.OauthHost = "http://localhost:3000"
    tn.ClientID = "403"
    tn.Secret = "554444vfg55ggfff22454sw2fff2dsfd"
    token := tn.ClientCredentialsToken()

Password Grant Type

Not supported

Returned Token for grant types Auth Code, Refresh, and Client Credentials

type Token struct {
    AccessToken   string `json:"access_token"`
    RefreshToken  string `json:"refresh_token"`
    TokenType     string `json:"token_type"`
    ExpiresIn     int    `json:"expires_in"`
    ErrorReturned string `json:"error"`
}

Returned by Implicit

Implicit grand type calls the redirect URI and passes the token as a query parm.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthCodeAuthorize

type AuthCodeAuthorize struct {
	OauthHost   string
	RedirectURI string
	ClientID    string
	Scope       string
	State       string
	OverrideURI string
	Req         *http.Request
	Res         http.ResponseWriter
}

AuthCodeAuthorize auth code

func (*AuthCodeAuthorize) AuthCodeAuthorizeUser

func (a *AuthCodeAuthorize) AuthCodeAuthorizeUser() bool

AuthCodeAuthorizeUser authorize a user with grant type code

func (*AuthCodeAuthorize) GetNew

func (a *AuthCodeAuthorize) GetNew() AuthCodeUser

GetNew GetNew

func (*AuthCodeAuthorize) SetClientID added in v1.0.2

func (a *AuthCodeAuthorize) SetClientID(id string)

SetClientID SetClientID

func (*AuthCodeAuthorize) SetOauthHost added in v1.0.2

func (a *AuthCodeAuthorize) SetOauthHost(host string)

SetOauthHost SetOauthHost

func (*AuthCodeAuthorize) SetOverrideURI added in v1.0.2

func (a *AuthCodeAuthorize) SetOverrideURI(uri string)

SetOverrideURI SetOverrideURI

func (*AuthCodeAuthorize) SetRedirectURI added in v1.0.2

func (a *AuthCodeAuthorize) SetRedirectURI(uri string)

SetRedirectURI SetRedirectURI

func (*AuthCodeAuthorize) SetReq added in v1.0.2

func (a *AuthCodeAuthorize) SetReq(r *http.Request)

SetReq SetReq

func (*AuthCodeAuthorize) SetRes added in v1.0.2

func (a *AuthCodeAuthorize) SetRes(w http.ResponseWriter)

SetRes SetRes

func (*AuthCodeAuthorize) SetScope added in v1.0.2

func (a *AuthCodeAuthorize) SetScope(scope string)

SetScope SetScope

func (*AuthCodeAuthorize) SetState added in v1.0.2

func (a *AuthCodeAuthorize) SetState(state string)

SetState SetState

type AuthCodeToken

type AuthCodeToken struct {
	OauthHost    string
	RedirectURI  string
	ClientID     string
	Secret       string
	Code         string
	RefreshToken string
	OverrideURI  string
}

AuthCodeToken auth code token

func (*AuthCodeToken) AuthCodeRefreshToken

func (t *AuthCodeToken) AuthCodeRefreshToken() *Token

AuthCodeRefreshToken get refresh token

func (*AuthCodeToken) AuthCodeToken

func (t *AuthCodeToken) AuthCodeToken() *Token

AuthCodeToken auth code token

func (*AuthCodeToken) GetNew

func (t *AuthCodeToken) GetNew() AuthToken

GetNew GetNew

func (*AuthCodeToken) SetClientID added in v1.0.2

func (t *AuthCodeToken) SetClientID(id string)

SetClientID SetClientID

func (*AuthCodeToken) SetCode added in v1.0.2

func (t *AuthCodeToken) SetCode(code string)

SetCode SetCode

func (*AuthCodeToken) SetOauthHost added in v1.0.2

func (t *AuthCodeToken) SetOauthHost(host string)

SetOauthHost SetOauthHost

func (*AuthCodeToken) SetOverrideURI added in v1.0.2

func (t *AuthCodeToken) SetOverrideURI(uri string)

SetOverrideURI SetOverrideURI

func (*AuthCodeToken) SetRedirectURI added in v1.0.2

func (t *AuthCodeToken) SetRedirectURI(uri string)

SetRedirectURI SetRedirectURI

func (*AuthCodeToken) SetRefreshToken added in v1.0.2

func (t *AuthCodeToken) SetRefreshToken(tkn string)

SetRefreshToken SetRefreshToken

func (*AuthCodeToken) SetSecret added in v1.0.2

func (t *AuthCodeToken) SetSecret(sec string)

SetSecret SetSecret

type AuthCodeUser

type AuthCodeUser interface {
	AuthCodeAuthorizeUser() bool
	SetOauthHost(host string)
	SetRedirectURI(uri string)
	SetClientID(id string)
	SetScope(scope string)
	SetState(state string)
	SetOverrideURI(uri string)
	SetReq(r *http.Request)
	SetRes(w http.ResponseWriter)
}

AuthCodeUser AuthCodeUser

type AuthToken

type AuthToken interface {
	AuthCodeToken() *Token
	AuthCodeRefreshToken() *Token
	SetOauthHost(host string)
	SetRedirectURI(uri string)
	SetClientID(id string)
	SetSecret(sec string)
	SetCode(code string)
	SetRefreshToken(tkn string)
	SetOverrideURI(uri string)
}

AuthToken AuthCodeToken

type ClientCredentialsToken

type ClientCredentialsToken struct {
	OauthHost   string
	ClientID    string
	Secret      string
	OverrideURI string
}

ClientCredentialsToken client credentials token

func (*ClientCredentialsToken) ClientCredentialsToken

func (c *ClientCredentialsToken) ClientCredentialsToken() *Token

ClientCredentialsToken get client credentials token

func (*ClientCredentialsToken) GetNew

func (c *ClientCredentialsToken) GetNew() Credentials

GetNew GetNew

func (*ClientCredentialsToken) SetClientID added in v1.0.2

func (c *ClientCredentialsToken) SetClientID(id string)

SetClientID SetClientID

func (*ClientCredentialsToken) SetOauthHost added in v1.0.2

func (c *ClientCredentialsToken) SetOauthHost(host string)

SetOauthHost SetOauthHost

func (*ClientCredentialsToken) SetOverrideURI added in v1.0.2

func (c *ClientCredentialsToken) SetOverrideURI(uri string)

SetOverrideURI SetOverrideURI

func (*ClientCredentialsToken) SetSecret added in v1.0.2

func (c *ClientCredentialsToken) SetSecret(sec string)

SetSecret SetSecret

type Credentials

type Credentials interface {
	ClientCredentialsToken() *Token
	SetOauthHost(host string)
	SetClientID(id string)
	SetSecret(sec string)
	SetOverrideURI(uri string)
}

Credentials Credentials

type Implicit

type Implicit interface {
	ImplicitAuthorize() bool
	SetOauthHost(host string)
	SetRedirectURI(uri string)
	SetClientID(id string)
	SetScope(scope string)
	SetState(state string)
	SetOverrideURI(uri string)
	SetReq(r *http.Request)
	SetRes(w http.ResponseWriter)
}

Implicit Implicit

type ImplicitAuthorize

type ImplicitAuthorize struct {
	OauthHost   string
	RedirectURI string
	ClientID    string
	Scope       string
	State       string
	OverrideURI string
	Req         *http.Request
	Res         http.ResponseWriter
}

ImplicitAuthorize implicit authorize

func (*ImplicitAuthorize) GetNew

func (i *ImplicitAuthorize) GetNew() Implicit

GetNew GetNew

func (*ImplicitAuthorize) ImplicitAuthorize

func (i *ImplicitAuthorize) ImplicitAuthorize() bool

ImplicitAuthorize implicit authorize

func (*ImplicitAuthorize) SetClientID added in v1.0.2

func (i *ImplicitAuthorize) SetClientID(id string)

SetClientID SetClientID

func (*ImplicitAuthorize) SetOauthHost added in v1.0.2

func (i *ImplicitAuthorize) SetOauthHost(host string)

SetOauthHost SetOauthHost

func (*ImplicitAuthorize) SetOverrideURI added in v1.0.2

func (i *ImplicitAuthorize) SetOverrideURI(uri string)

SetOverrideURI SetOverrideURI

func (*ImplicitAuthorize) SetRedirectURI added in v1.0.2

func (i *ImplicitAuthorize) SetRedirectURI(uri string)

SetRedirectURI SetRedirectURI

func (*ImplicitAuthorize) SetReq added in v1.0.2

func (i *ImplicitAuthorize) SetReq(r *http.Request)

SetReq SetReq

func (*ImplicitAuthorize) SetRes added in v1.0.2

func (i *ImplicitAuthorize) SetRes(w http.ResponseWriter)

SetRes SetRes

func (*ImplicitAuthorize) SetScope added in v1.0.2

func (i *ImplicitAuthorize) SetScope(scope string)

SetScope SetScope

func (*ImplicitAuthorize) SetState added in v1.0.2

func (i *ImplicitAuthorize) SetState(state string)

SetState SetState

type MockAuthCodeAuthorize

type MockAuthCodeAuthorize struct {
	OauthHost   string
	RedirectURI string
	ClientID    string
	Scope       string
	State       string
	OverrideURI string
	Req         *http.Request
	Res         http.ResponseWriter
	MockRtn     bool
}

MockAuthCodeAuthorize auth code

func (*MockAuthCodeAuthorize) AuthCodeAuthorizeUser

func (a *MockAuthCodeAuthorize) AuthCodeAuthorizeUser() bool

AuthCodeAuthorizeUser authorize a user with grant type code

func (*MockAuthCodeAuthorize) GetNew

func (a *MockAuthCodeAuthorize) GetNew() AuthCodeUser

GetNew GetNew

func (*MockAuthCodeAuthorize) SetClientID added in v1.0.2

func (a *MockAuthCodeAuthorize) SetClientID(id string)

SetClientID SetClientID

func (*MockAuthCodeAuthorize) SetOauthHost added in v1.0.2

func (a *MockAuthCodeAuthorize) SetOauthHost(host string)

SetOauthHost SetOauthHost

func (*MockAuthCodeAuthorize) SetOverrideURI added in v1.0.2

func (a *MockAuthCodeAuthorize) SetOverrideURI(uri string)

SetOverrideURI SetOverrideURI

func (*MockAuthCodeAuthorize) SetRedirectURI added in v1.0.2

func (a *MockAuthCodeAuthorize) SetRedirectURI(uri string)

SetRedirectURI SetRedirectURI

func (*MockAuthCodeAuthorize) SetReq added in v1.0.2

func (a *MockAuthCodeAuthorize) SetReq(r *http.Request)

SetReq SetReq

func (*MockAuthCodeAuthorize) SetRes added in v1.0.2

SetRes SetRes

func (*MockAuthCodeAuthorize) SetScope added in v1.0.2

func (a *MockAuthCodeAuthorize) SetScope(scope string)

SetScope SetScope

func (*MockAuthCodeAuthorize) SetState added in v1.0.2

func (a *MockAuthCodeAuthorize) SetState(state string)

SetState SetState

type MockAuthCodeToken

type MockAuthCodeToken struct {
	OauthHost    string
	RedirectURI  string
	ClientID     string
	Secret       string
	Code         string
	RefreshToken string
	OverrideURI  string
	MockToken    *Token
}

MockAuthCodeToken auth code token

func (*MockAuthCodeToken) AuthCodeRefreshToken

func (t *MockAuthCodeToken) AuthCodeRefreshToken() *Token

AuthCodeRefreshToken get refresh token

func (*MockAuthCodeToken) AuthCodeToken

func (t *MockAuthCodeToken) AuthCodeToken() *Token

AuthCodeToken auth code token

func (*MockAuthCodeToken) GetNew

func (t *MockAuthCodeToken) GetNew() AuthToken

GetNew GetNew

func (*MockAuthCodeToken) SetClientID added in v1.0.2

func (t *MockAuthCodeToken) SetClientID(id string)

SetClientID SetClientID

func (*MockAuthCodeToken) SetCode added in v1.0.2

func (t *MockAuthCodeToken) SetCode(code string)

SetCode SetCode

func (*MockAuthCodeToken) SetOauthHost added in v1.0.2

func (t *MockAuthCodeToken) SetOauthHost(host string)

SetOauthHost SetOauthHost

func (*MockAuthCodeToken) SetOverrideURI added in v1.0.2

func (t *MockAuthCodeToken) SetOverrideURI(uri string)

SetOverrideURI SetOverrideURI

func (*MockAuthCodeToken) SetRedirectURI added in v1.0.2

func (t *MockAuthCodeToken) SetRedirectURI(uri string)

SetRedirectURI SetRedirectURI

func (*MockAuthCodeToken) SetRefreshToken added in v1.0.2

func (t *MockAuthCodeToken) SetRefreshToken(tkn string)

SetRefreshToken SetRefreshToken

func (*MockAuthCodeToken) SetSecret added in v1.0.2

func (t *MockAuthCodeToken) SetSecret(sec string)

SetSecret SetSecret

type MockClientCredentialsToken

type MockClientCredentialsToken struct {
	OauthHost   string
	ClientID    string
	Secret      string
	OverrideURI string
	MockToken   *Token
}

MockClientCredentialsToken client credentials token

func (*MockClientCredentialsToken) ClientCredentialsToken

func (c *MockClientCredentialsToken) ClientCredentialsToken() *Token

ClientCredentialsToken get client credentials token

func (*MockClientCredentialsToken) GetNew

GetNew GetNew

func (*MockClientCredentialsToken) SetClientID added in v1.0.2

func (c *MockClientCredentialsToken) SetClientID(id string)

SetClientID SetClientID

func (*MockClientCredentialsToken) SetOauthHost added in v1.0.2

func (c *MockClientCredentialsToken) SetOauthHost(host string)

SetOauthHost SetOauthHost

func (*MockClientCredentialsToken) SetOverrideURI added in v1.0.2

func (c *MockClientCredentialsToken) SetOverrideURI(uri string)

SetOverrideURI SetOverrideURI

func (*MockClientCredentialsToken) SetSecret added in v1.0.2

func (c *MockClientCredentialsToken) SetSecret(sec string)

SetSecret SetSecret

type MockImplicitAuthorize

type MockImplicitAuthorize struct {
	OauthHost   string
	RedirectURI string
	ClientID    string
	Scope       string
	State       string
	OverrideURI string
	Req         *http.Request
	Res         http.ResponseWriter
	MockRtn     bool
}

MockImplicitAuthorize implicit authorize

func (*MockImplicitAuthorize) GetNew

func (i *MockImplicitAuthorize) GetNew() Implicit

GetNew GetNew

func (*MockImplicitAuthorize) ImplicitAuthorize

func (i *MockImplicitAuthorize) ImplicitAuthorize() bool

ImplicitAuthorize implicit authorize

func (*MockImplicitAuthorize) SetClientID added in v1.0.2

func (i *MockImplicitAuthorize) SetClientID(id string)

SetClientID SetClientID

func (*MockImplicitAuthorize) SetOauthHost added in v1.0.2

func (i *MockImplicitAuthorize) SetOauthHost(host string)

SetOauthHost SetOauthHost

func (*MockImplicitAuthorize) SetOverrideURI added in v1.0.2

func (i *MockImplicitAuthorize) SetOverrideURI(uri string)

SetOverrideURI SetOverrideURI

func (*MockImplicitAuthorize) SetRedirectURI added in v1.0.2

func (i *MockImplicitAuthorize) SetRedirectURI(uri string)

SetRedirectURI SetRedirectURI

func (*MockImplicitAuthorize) SetReq added in v1.0.2

func (i *MockImplicitAuthorize) SetReq(r *http.Request)

SetReq SetReq

func (*MockImplicitAuthorize) SetRes added in v1.0.2

SetRes SetRes

func (*MockImplicitAuthorize) SetScope added in v1.0.2

func (i *MockImplicitAuthorize) SetScope(scope string)

SetScope SetScope

func (*MockImplicitAuthorize) SetState added in v1.0.2

func (i *MockImplicitAuthorize) SetState(state string)

SetState SetState

type Token

type Token struct {
	AccessToken   string `json:"access_token"`
	RefreshToken  string `json:"refresh_token"`
	TokenType     string `json:"token_type"`
	ExpiresIn     int    `json:"expires_in"`
	ErrorReturned string `json:"error"`
}

Token the access token

Jump to

Keyboard shortcuts

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