ezralazuardy / heimdall

Painless OAuth 2.0 Server for CodeIgniter 4 🔥
https://heimdall.lazuardy.tech
MIT License
41 stars 10 forks source link

Multiple Grant Type Support in Heimdall #19

Open doelmi opened 2 years ago

doelmi commented 2 years ago

Is your feature request related to a problem? Please describe.

I want to have multiple grant type in one server, is there any good example to do it?

Describe the solution you'd like

I have done it, but with condition from what grant_type value is.

// function to create a new instance of HeimdallAuthorizationServer
    static function createAuthorizationServer($grant_type = null)
    {
        // creating HeimdallAuthorizationServer config
        $config = Heimdall::withAuthorizationConfig(
            new ClientRepository(),
            new AccessTokenRepository(),
            new ScopeRepository(),
            __DIR__ . '/private.key'
        );

        $grant = null;
        switch ($grant_type) {
            case 'client_credentials':
                $grant = Heimdall::withClientCredentialsGrant('P1Y');
                break;
            default:
                // creating HeimdallAuthorizationServer grant
                $grant = Heimdall::withAuthorizationCodeGrant(
                    new AuthCodeRepository(),
                    new RefreshTokenRepository(),
                    'PT1H',
                    'P6M',
                    'P3M'
                );
                break;
        }

        // return a new instance of HeimdallAuthorizationServer
        return Heimdall::initializeAuthorizationServer($config, $grant);
    }

Describe alternatives you've considered

Instead of using condition above, is there any other solution, that can make multiple grant_type support?

Additional context

In League Library source code, it is possible to do it. What's about implementation in Heimdall?