Skip to content

Authorization Code Grant

RFC 6749 §4.1 · package rfc6749/authorization_code

Implements the Authorization Code Grant. See OAuth 2.0 Flows for how this grant works conceptually, and Config + Flow Pattern for the general construction shape used here.

Construction

go
import authorizationcode "github.com/alkeyio/authkit/rfc6749/authorization_code"

cfg := authorizationcode.NewConfig().
    SetClientManager(clientMgr).
    SetAuthCodeManager(authCodeMgr).
    SetTokenManager(tokenMgr)

flow, err := authorizationcode.Must(cfg)

Required dependencies

SetterManager interfacePurpose
SetClientManagerClientManagerLook up registered clients and their redirect URIs.
SetAuthCodeManagerAuthCodeManagerPersist and redeem issued authorization codes.
SetTokenManagerTokenManagerIssue and persist access/refresh tokens.

See Models for the full interface definitions.

Extensions

Register any combination of extensions that implement the relevant interfaces (see Extension System):

go
cfg.RegisterExtension(pkce) // github.com/alkeyio/authkit/rfc7636
cfg.RegisterExtension(oidc) // github.com/alkeyio/authkit/oidc/core/authorization_code

Most deployments register both — see the full example.

Registering with a server

go
srv := authkit.NewServer()
srv.RegisterGrant(flow)

This makes the flow available through srv.CreateAuthorizationResponse, srv.CreateConsentResponse, and srv.CreateTokenResponse. See Server.

Released under the BSD-3-Clause License.