How to obtain authorize code and access token to send a message in a channel in Teams through HTTP Request API

sumitendra.singh 1 Reputation point
2023-01-10T06:46:13.64+00:00

I Registered An app in Azure with Accounts in any organizational directory (Any Azure AD directory - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox) , Account Type using email - xxxxxx@harsh.com .com.

Also i am giving following API permissions for my Azure App which i am showing in my screenshot ![277805-screenshot-119.png][1]

But when i make a POST request using this http request https://graph.microsoft.com/v1.0/teams/fbe2bf47-16c8-47cf-b4a5-4b9b187c508b/channels/19:4a95f7d8db4c4e7fae857bcebe0623e6@thread.tacv2/messages in POSTMAN using following request headers in Authorization with OAuth2.0 Type

Token Name - devops

Callback URL - https://oauth.pstmn.io/v1/browser-callback

Auth URL - https://login.microsoftonline.com/f8cdef31-a31e-4b4a-93e4-5f571e91255a/oauth2/v2.0/authorize

Access Token URL - https://login.microsoftonline.com/f8cdef31-a31e-4b4a-93e4-5f571e91255a/oauth2/v2.0/token

Client ID of my Azure App

Client Secret of my Azure App

Scope - ChannelMessage.Send

But when i click Get New Access Token in POSTMAN it redirect to sign in to your account window. But when i login using my xxxxx@harsh.com .com it shows the following error which i am showing in attached screen shot. ![277686-screenshot-113.png][2]

Here i am showing how i am trying to get access token through POSTMAN ![277639-screenshot-115.png][3] ![277619-screenshot-116.png][4]

I also tried to obtain authorize code using HTTP GET request using curl PHP with Content-Type: application/x-www-form-urlencoded which i am showing in my screenshot how i am sending GET Request to obtain authorize code ![277687-screenshot-118.png][5]

but when i hit my php file it redirects to sign in window and when i sign in using my email - sumit.trueworks@harsh.com .com , it doesn't let me sign in which i am showing in my screen shot ![277781-screenshot-114.png][6]

Sir please assist me how to obtain authorize code and access token to send message in channel in teams through HTTP POST Request.

Sir please reach me out through my email - ******@trueworks.in

Sir it is my humble request to solve my above query as soon as possible by which i can start my work further.

yours sincerely

Sumitendra Singh

Email - ******@trueworks.in

Microsoft Teams | Development
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 46,376 Reputation points
    2023-01-12T10:37:19.8366667+00:00

    Hi @sumitendra.singh

    The authorization code is obtained by interactively logging in the user in the browser and not in postman, so you need to run the authorization URL in the browser and log in to the user:

    https://login.microsoftonline.com/{tenant id}/oauth2/v2.0/authorize?
    client_id={client id}
    &response_type=code
    &redirect_uri={redirect url}
    &response_mode=query
    &scope=ChannelMessage.Send
    &state=12345
    

    Since sending chat messages in channels does not support personal accounts, if your account(******@harsh.com) is a personal account, you need to add your personal account as a guest to the tenant before obtaining an authorization code and access token.

    User's image


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.