We want a token which should be used in python sdk to send messages using graph api.

Gerald Donnini 0 Reputation points
2025-05-21T10:06:04.75+00:00

We are integrating ms team chat system in our django based web application using graph api for ms teams but we are not able to get a token or key which will be used every time to send messages in Channel and receive messages from channel itself.

Additionally when we are using Access Token after successful login to https://developer.microsoft.com/en-us/graph/graph-explorer#access_token
It is valid for only 24 hours after every 24 hours we need to get this token and need to add in our web application is there a way using any API we can get that token so that it don't get expired or can you provide any token with lifetime validity.

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

1 answer

Sort by: Most helpful
  1. Sayali-MSFT 3,991 Reputation points Microsoft External Staff Moderator
    2025-05-21T12:26:52.6433333+00:00

    Hello Gerald Donnini, you cannot get a Microsoft Graph access token that never expires. For security, all access tokens are short-lived (usually 1 hour). What you need is to implement the OAuth 2.0 authorization flow with a refresh token.
    A refresh token is used to obtain new access and refresh token pairs when the current access token expires. When a client acquires an access token to access a protected resource, the client also receives a refresh token.

    Reference Document-

    1. https://learn.microsoft.com/en-us/entra/identity-platform/refresh-tokens
    2. https://learn.microsoft.com/en-us/entra/identity-platform/access-tokens#token-lifetime
    0 comments No comments

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.