Skip to content

feat(manage): add SetGrantTypeTokenCfg for custom grant type support#295

Open
SxxSolar wants to merge 1 commit into
go-oauth2:masterfrom
SxxSolar:custom-grant-type-support-9718
Open

feat(manage): add SetGrantTypeTokenCfg for custom grant type support#295
SxxSolar wants to merge 1 commit into
go-oauth2:masterfrom
SxxSolar:custom-grant-type-support-9718

Conversation

@SxxSolar
Copy link
Copy Markdown

Summary

  • Add SetGrantTypeTokenCfg(gt oauth2.GrantType, cfg *Config) method to Manager struct to enable custom grant type configuration

Problem

The Manager struct has a private gtcfg field (map[oauth2.GrantType]*Config), but only provides configuration methods for the 4 standard OAuth2 grant types:

  • SetAuthorizeCodeTokenCfg
  • SetImplicitTokenCfg
  • SetPasswordTokenCfg
  • SetClientTokenCfg

This design prevents users from configuring custom grant types, which is a common requirement in OAuth2 implementations (e.g., device_code, urn:ietf:params:oauth:grant-type:jwt-bearer, etc.).

Solution

Add a generic SetGrantTypeTokenCfg(gt oauth2.GrantType, cfg *Config) method that allows users to configure token settings for any grant type, including custom ones.

Usage Example

// Define a custom grant type
const DeviceCodeGrant oauth2.GrantType = "urn:ietf:params:oauth:grant-type:device_code"
 
// Configure the custom grant type
manager.SetGrantTypeTokenCfg(DeviceCodeGrant, &manage.Config{
    AccessTokenExp:    time.Hour * 2,
    RefreshTokenExp:   time.Hour * 24 * 7,
    IsGenerateRefresh: true,
})

The Manager struct has a private gtcfg field (map[oauth2.GrantType]*Config),
but only provides configuration methods for the 4 standard OAuth2 grant types:
- SetAuthorizeCodeTokenCfg
- SetImplicitTokenCfg
- SetPasswordTokenCfg
- SetClientTokenCfg

This prevents users from configuring custom grant types. This commit adds
a generic SetGrantTypeTokenCfg(gt GrantType, cfg *Config) method that allows
users to configure token settings for any grant type, including custom ones.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants