Search code examples
azureoauth-2.0slackslack-apiazure-authentication

How to integrate the o365/m365 oauth flow with my slack app


I'm writing an app which will allow me to get specific data from outlook/exchange using the EWS on behalf of a slack/outlook/exchange user. to authenticate via Microsoft’s oauth flow I created a azure a client_id and would like to initiate the oauth flow for m265 from the apps Home Screen. In order to create the client I’d I also need to provide a redirect url within azure ad.

Where can I find documentation on how to best use external oauth flows? (This is not about installing/authorizing the app within slack).

I’d like to add a "connect to outlook" button on my apps home page after installing from which to start the flow.

Shall I call the Microsoft login (oauth) url directly or should I first link to my apps web server? When calling the microsoft login I need to provide a redirect url (which needs to match the one in azure ad) to which the authorization codes gets returned.

For some apps (e.g. outlook calendar for slack) this seems be a slack url.

servicenow seems to use something like…

Is there a way to define such an url for my app within slack? How will the authorization code be handed over to my app (I assume to the Request url I defined for my app…?

Thank you for time and consideration..


Solution

  • • I am considering here that you are providing authentication for your application through Azure AD, thus, to configure redirect URIs after authorization code or token is received post successful authentication, please refer the below documentation on redirect URIs. It specifies in detail the configuration restrictions that should be followed while configuring a redirect URL in Azure AD: -

    https://learn.microsoft.com/en-us/azure/active-directory/develop/reply-url

    Similarly, to configure a redirect URL for an application in Slack, please check the callback URL settings configured because it is required while redirect URL is an optional thing. Also, Slack will redirect the users to the callback URL itself configured in app settings if redirect URL is absent. And if provided, the redirect URL's host and port must exactly match the callback URL. The redirect URL's path must reference a subdirectory of the callback URL. Please follow the below link for more information: -

    https://api.slack.com/legacy/oauth

    In the above URL, go to ‘Using access tokens’ and ‘Redirect URLs’ section for exact information.

    • And as far as calling the Microsoft login (OAuth)URL directly or linking it to your app’s web server, I would suggest you provision your Azure AD users in Slack by following the below documentation link or configure SSO with Slack by adding it in Enterprise Applications in Azure AD from application gallery and then configure the API permissions required for accessing the data from Exchange through EWS. In this way, proper configuration and redirection can be achieved for the users which are allowed to access the specific data from Exchange.

    https://learn.microsoft.com/en-us/azure/active-directory/saas-apps/slack-tutorial

    https://learn.microsoft.com/en-us/azure/active-directory/saas-apps/slack-provisioning-tutorial