Skip to content

Commit

Permalink
flame: added callback
Browse files Browse the repository at this point in the history
  • Loading branch information
256dpi committed Dec 4, 2023
1 parent c2acb75 commit 2c60d42
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions flame/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ func (a *Authenticator) authorizationEndpoint(ctx *Context) {
res := a.issueTokens(ctx, false, scope, req.RedirectURI, client, resourceOwner)
res.SetRedirect(req.RedirectURI, req.State)

// invoke callback if available
if a.policy.TokensIssued != nil {
xo.AbortIf(a.policy.TokensIssued(ctx, client, resourceOwner, scope))
}

// write response
xo.AbortIf(oauth2.WriteTokenResponse(ctx.writer, res))
case oauth2.CodeResponseType:
Expand Down Expand Up @@ -485,6 +490,11 @@ func (a *Authenticator) handleResourceOwnerPasswordCredentialsGrant(ctx *Context
// issue access token
res := a.issueTokens(ctx, true, scope, "", client, resourceOwner)

// invoke callback if available
if a.policy.TokensIssued != nil {
xo.AbortIf(a.policy.TokensIssued(ctx, client, resourceOwner, scope))
}

// write response
xo.AbortIf(oauth2.WriteTokenResponse(ctx.writer, res))
}
Expand Down Expand Up @@ -517,6 +527,11 @@ func (a *Authenticator) handleClientCredentialsGrant(ctx *Context, req *oauth2.T
// issue access token
res := a.issueTokens(ctx, true, scope, "", client, nil)

// invoke callback if available
if a.policy.TokensIssued != nil {
xo.AbortIf(a.policy.TokensIssued(ctx, client, nil, scope))
}

// write response
xo.AbortIf(oauth2.WriteTokenResponse(ctx.writer, res))
}
Expand Down Expand Up @@ -585,6 +600,11 @@ func (a *Authenticator) handleRefreshTokenGrant(ctx *Context, req *oauth2.TokenR
// delete refresh token
a.deleteToken(ctx, rt.ID())

// invoke callback if available
if a.policy.TokensIssued != nil {
xo.AbortIf(a.policy.TokensIssued(ctx, client, ro, req.Scope))
}

// write response
xo.AbortIf(oauth2.WriteTokenResponse(ctx.writer, res))
}
Expand Down Expand Up @@ -669,6 +689,11 @@ func (a *Authenticator) handleAuthorizationCodeGrant(ctx *Context, req *oauth2.T
// delete authorization code
a.deleteToken(ctx, code.ID())

// invoke callback if available
if a.policy.TokensIssued != nil {
xo.AbortIf(a.policy.TokensIssued(ctx, client, ro, req.Scope))
}

// write response
xo.AbortIf(oauth2.WriteTokenResponse(ctx.writer, res))
}
Expand Down
3 changes: 3 additions & 0 deletions flame/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ type Policy struct {
// owner to give the approval.
ApproveStrategy func(ctx *Context, c Client, ro ResourceOwner, token GenericToken, scope oauth2.Scope) (oauth2.Scope, error)

// TokensIssued is invoked after tokens haven been issued.
TokensIssued func(ctx *Context, c Client, ro ResourceOwner, scope oauth2.Scope) error

// TokenData may return a map of data that should be included in the
// generated JWT tokens as the "dat" field as well as in the token
// introspection's response "extra" field.
Expand Down

0 comments on commit 2c60d42

Please sign in to comment.