Documentation
¶
Index ¶
- Constants
- Variables
- func Error(w http.ResponseWriter, error string, statusCode int)
- func GenerateSecret() string
- func RedirectError(w http.ResponseWriter, r *http.Request, redirectURI string, error string)
- type AuthCodeOption
- type AuthStyle
- type AuthorizationServer
- type AuthorizationServerOption
- type Client
- type CodeIssuer
- type Config
- type Endpoint
- type JSONWebKey
- type JSONWebKeySet
- type Logger
- type RetrieveError
- type Token
- type TokenSource
- type Transport
Examples ¶
Constants ¶
const ( ErrorInvalidClient = "invalid_client" ErrorInvalidGrant = "invalid_grant" )
Variables ¶
var ( ErrClientNotFound = errors.New("client not found") ErrInvalidBasicAuthentication = errors.New("invalid or missing basic authentication") )
Functions ¶
func GenerateSecret ¶ added in v0.5.0
func GenerateSecret() string
func RedirectError ¶ added in v0.5.0
Types ¶
type AuthCodeOption ¶ added in v0.3.0
type AuthCodeOption = oauth2.AuthCodeOption
AuthCodeOption is a type alias for https://pkg.go.dev/golang.org/x/oauth2#AuthCodeOption.
type AuthStyle ¶ added in v0.2.0
AuthStyle is a type alias for https://pkg.go.dev/golang.org/x/oauth2#AuthStyle.
type AuthorizationServer ¶ added in v0.2.0
AuthorizationServer is an OAuth 2.0 authorization server
Example ¶
ExampleLoginPage sets up an OAuth 2.0 authorization server with an integrated login page (acting as an authentication server).
package main import ( "fmt" oauth2 "github.com/oxisto/oauth2go" "github.com/oxisto/oauth2go/login" ) func main() { var srv *oauth2.AuthorizationServer var port = 8080 srv = oauth2.NewServer(fmt.Sprintf(":%d", port), login.WithLoginPage(login.WithUser("admin", "admin")), ) fmt.Printf("Creating new OAuth 2.0 server on %d", port) go srv.ListenAndServe() defer srv.Close() }
Output: Creating new OAuth 2.0 server on 8080
func NewServer ¶
func NewServer(addr string, opts ...AuthorizationServerOption) *AuthorizationServer
func (*AuthorizationServer) GetClient ¶ added in v0.5.0
func (srv *AuthorizationServer) GetClient(clientID string) (*Client, error)
GetClient returns the client for the given ID or ErrClientNotFound.
func (*AuthorizationServer) IssueCode ¶ added in v0.5.0
func (srv *AuthorizationServer) IssueCode() (code string)
IssueCode implements CodeIssuer.
func (*AuthorizationServer) PublicKeys ¶ added in v0.5.0
func (srv *AuthorizationServer) PublicKeys() []*ecdsa.PublicKey
PublicKey returns the public keys of the signing key of this authorization server.
func (*AuthorizationServer) ValidateCode ¶ added in v0.5.0
func (srv *AuthorizationServer) ValidateCode(code string) bool
ValidateCode implements CodeIssuer. It checks if the code exists and is not expired. If the code exists, it will be invalidated after this call.
type AuthorizationServerOption ¶ added in v0.2.0
type AuthorizationServerOption func(srv *AuthorizationServer)
func WithClient ¶
func WithClient( clientID string, clientSecret string, redirectURI string, ) AuthorizationServerOption
type CodeIssuer ¶ added in v0.5.0
type Config ¶ added in v0.2.0
Config is a type alias for https://pkg.go.dev/golang.org/x/oauth2#Config.
type Endpoint ¶ added in v0.2.0
Endpoint is a type alias for https://pkg.go.dev/golang.org/x/oauth2#Endpoint.
type JSONWebKey ¶
type JSONWebKey struct { Kid string `json:"kid"` Kty string `json:"kty"` X string `json:"x"` Y string `json:"y"` }
JSONWebKey is a JSON Web Key that only supports elliptic curve keys for now.
type JSONWebKeySet ¶ added in v0.3.0
type JSONWebKeySet struct {
Keys []JSONWebKey `json:"keys"`
}
JSONWebKeySet is a JSON Web Key Set.
type RetrieveError ¶ added in v0.3.0
type RetrieveError = oauth2.RetrieveError
RetrieveError is a type alias for https://pkg.go.dev/golang.org/x/oauth2#RetrieveError.
type Token ¶ added in v0.3.0
Token is a type alias for https://pkg.go.dev/golang.org/x/oauth2#Token.
type TokenSource ¶ added in v0.3.0
type TokenSource = oauth2.TokenSource
TokenSource is a type alias for https://pkg.go.dev/golang.org/x/oauth2#TokenSource.
type Transport ¶ added in v0.3.0
Transport is a type alias for https://pkg.go.dev/golang.org/x/oauth2#Transport.
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
internal
|
|
mock
package mock contains several structs that are used in various unit tests
|
package mock contains several structs that are used in various unit tests |
package login contains an optional "login" (authentication) server that can be used.
|
package login contains an optional "login" (authentication) server that can be used. |