flame/callback.go
func Callback(force bool, scope ...string) *fire.Callback {
	return fire.C("flame/Callback", fire.All(), func(ctx *fire.Context) error {
		// coerce scope
		s := oauth2.Scope(scope)

		// get access token
		accessToken, _ := ctx.HTTPRequest.Context().Value(AccessTokenContextKey).(GenericToken)

		// check access token
		if accessToken == nil {
			// return error if authentication is required
			if force {
				return fire.ErrAccessDenied
			}

			return nil
		}

		// validate scope
		_, scope, _, _, _ := accessToken.GetTokenData()
		if !oauth2.Scope(scope).Includes(s) {
			return fire.ErrAccessDenied
		}

		// get client
		client := ctx.HTTPRequest.Context().Value(ClientContextKey).(Client)

		// get resource owner
		resourceOwner, _ := ctx.HTTPRequest.Context().Value(ResourceOwnerContextKey).(ResourceOwner)

		// store auth info
		ctx.Data[AuthInfoDataKey] = &AuthInfo{
			Client:        client,
			ResourceOwner: resourceOwner,
			AccessToken:   accessToken,
		}

		return nil
	})
}
func Callback(force bool, scope ...string) *fire.Callback {
	return fire.C("flame/Callback", fire.All(), func(ctx *fire.Context) error {
		// coerce scope
		s := oauth2.Scope(scope)

		// get access token
		accessToken, _ := ctx.HTTPRequest.Context().Value(AccessTokenContextKey).(GenericToken)

		// check access token
		if accessToken == nil {
			// return error if authentication is required
			if force {
				return fire.ErrAccessDenied
			}

			return nil
		}

		// validate scope
		_, scope, _, _, _ := accessToken.GetTokenData()
		if !oauth2.Scope(scope).Includes(s) {
			return fire.ErrAccessDenied
		}

		// get client
		client := ctx.HTTPRequest.Context().Value(ClientContextKey).(Client)

		// get resource owner
		resourceOwner, _ := ctx.HTTPRequest.Context().Value(ResourceOwnerContextKey).(ResourceOwner)

		// store auth info
		ctx.Data[AuthInfoDataKey] = &AuthInfo{
			Client:        client,
			ResourceOwner: resourceOwner,
			AccessToken:   accessToken,
		}

		return nil
	})
}
// Callback returns a callback that can be used in controllers to protect
// resources by requiring an access token with the provided scope to be granted.
//
// Note: The callback requires that the request has already been authorized
// using the Authorizer middleware from an Authenticator.