frankie567 / httpx-oauth

Async OAuth client using HTTPX
https://frankie567.github.io/httpx-oauth/
MIT License
136 stars 45 forks source link

Support custom authorization server for OKTA client #324

Open boubou191911 opened 3 months ago

boubou191911 commented 3 months ago

OKTA allows to define custom authorization server instead of using the organization authorization server. This is a usual practice when your OKTA server has to support the authorization process of several applications.

The .well-know URL has a different format for those servers. It would be nice to support them as well.

I have unfortunately no time to make a proper pull request. But here would be the code to implement this little change adding a 'auth_Server_id' parameter to the constructoR..

class OktaOAuth2(OpenID):
    def __init__(
        self,
        client_id: str,
        client_secret: str,
        okta_domain: str,
        auth_server_id: Optional[str] = None,
        scopes: Optional[List[str]] = BASE_SCOPES,
        name: str = "okta",
    ):
        well_known_url = f"https://{okta_domain}/.well-known/openid-configuration" if auth_server_id is None \
            else f"https://{okta_domain}/oauth2/{auth_server_id}/.well-known/openid-configuration"
        super().__init__(
            client_id,
            client_secret,
            well_known_url,
            name=name,
            base_scopes=scopes,
        )