MS Teams: Register App & Generate Token
Register an app
- 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.
- Select the Azure Active Directory.
- Select App Registrations.
- Select New Registration.
- 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 - Select Register.
Provide API Permission
- Copy Client ID and Tenant ID.
Cilent ID is mandatory for personal account.
- Click Certificates and Secret, and then click New Client Secret and copy value of the secret.
The value is visible only once.
- Click API Permission, and then click Add Permission Microsoft Graph.
- Provide all required permissions.
Provide the Grant admin consent for all permission using an admin account.
- 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
- 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
- After running the code in the browser the sign-in page appears. Enter the user details of the user who has created the app.
Admin User can also give the grant to the app.
- After signing in the Permissions requested page appears. Click Accept.
- 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: