Skip to main content

MS Teams: Register App & Generate Token

Register an app

  1. Sign in to Azure portal with the email address having permission to perform the action to be automated. The permission details are mentioned under the specific step documentation.
  2. Select the Azure Active Directory.
  3. Select App Registrations.
  4. Select New Registration.
  5. Name the application. Select a supported account type as Accounts in organizational directory only (…… - Single tenant), which determines who can use the application. Under Redirect URI, select Web for the type of application you want to create and provide valid URL.
    For example, https://automationedge.com
  6. Select Register.

Provide API Permission

  1. Copy Client ID and Tenant ID.
tip

Cilent ID is mandatory for personal account.


  1. Click Certificates and Secret, and then click New Client Secret and copy value of the secret.
tip

The value is visible only once.


  1. Click API Permission, and then click Add Permission  Microsoft Graph.
  2. Provide all required permissions.

tip

Provide the Grant admin consent for all permission using an admin account.

  1. Delegated offline_access permission is mandatory to generate the refresh token. To find the necessary permissions, see respective step documentation.

For more information, see https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app#register-an-application

For more information about redirect URI setup, see https://docs.microsoft.com/en-us/azure/active-directory/develop/reply-url

Generate Refresh Token URL and Run in browser

  1. Get an authorization code. To start the sign-in process with the code flow, use a web browser to load the URL request.

GET
https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/authorize?client_id={client_id}&scope={scope} &response_type=code

Example:

https://login.microsoftonline.com/96046-323f-4f98-91e6 fc1f2/oauth2/v2.0/authorize?client_id=bc096046-323f-4f98-91e6-fc1f28canks&scope=Channel.Create Channel.Delete.All Channel.ReadBasic.All ChannelMember.ReadWrite.All ChannelMessage.Edit ChannelMessage.Read.All ChannelMessage.ReadWrite ChannelMessage.Send ChannelSettings.Read.All ChannelSettings.ReadWrite.All Chat.ReadWrite ChatMessage.Send Directory.Read.All Directory.ReadWrite.All Group.ReadWrite.All offline_access Team.Create Team.ReadBasic.All TeamMember.Read.All TeamMember.ReadWrite.All User.Read &response_type=code
  1. After running the code in the browser the sign-in page appears. Enter the user details of the user who has created the app.
tip

Admin User can also give the grant to the app.


  1. After signing in the Permissions requested page appears. Click Accept.

  1. After clicking Accept, user is redirected to the URI provided during app creation. After you are redirected, you get the code in the address bar of the browser.

Redeem the code for access tokens and refresh token

After you receive the code value, you can redeem the code for a set of tokens that allow you to authenticate with the Microsoft Teams API. To redeem the code, make the following request:

POST
https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token

Headers:
Content-Type: application/x-www-form-urlencoded

Body: x-www-form-urlencoded
(key value pair) client_id={client_id} client_secret={client_secret} code={code} grant_type=authorization_code

Example: Postman Request:


Postman Response: