vapor-community / Imperial

Federated Authentication with OAuth providers
MIT License
153 stars 48 forks source link

Microsoft: Support custom tenant IDs #67

Closed cweinberger closed 4 years ago

cweinberger commented 4 years ago

Add support for Microsoft Tenant ID

In MicrosoftRouter the accessTokenURL was hardcoded to https://login.microsoftonline.com/common/oauth2/v2.0/token.

However, you can and should only use common if your app is configured as a multi-tenant application. For single-tenant applications you have to provide it in the accessTokenURL, e.g. https://login.microsoftonline.com/f8cdef31-a31e-4b4a-93e4-89f11e91255a/oauth2/v2.0/token, otherwise it fails with an error like this:

Application '(app ID)' is not configured as a multi-tenant application. Usage of the /common endpoint is not supported for such applications created after '10/15/2018'. Use a tenant-specific endpoint or configure the application to be multi-tenant."

This PR adds the possibility to change the tenant ID by providing it in MICROSOFT_TENANT_ID env var. If no tenant ID was provided it falls back to common (as before).

Considerations

I would probably have tenantID added to MicrosoftAuth or Microsoft. But these have to conform to FederatedServiceTokens / FederatedService and I couldn't change their required initializers etc.

Update .gitignore

Added .swiftpm folder to .gitignore