Prashant
Prashant

Reputation: 31

Microsoft Teams - how to get auth-token for api calls

I am developing a bot in Ms Teams using nodejs sdk v4, which fetches the list of all the team members using getPagedTeamMembers() and then for each member I want to get their conversation Id with the bot. I have found a way using api call to "serviceUrl/in/v3/conversations" but i don't know how to get the bearer auth-token for this api call.

Upvotes: 3

Views: 15212

Answers (2)

AndyNope
AndyNope

Reputation: 429

Nowadays you can use TeamsFX: https://learn.microsoft.com/en-en/microsoftteams/platform/toolkit/teamsfx-sdk

Example:

...
    export default function App() {

  const { loading, theme, themeString, teamsUserCredential } = useTeamsUserCredential({
    initiateLoginEndpoint: config.initiateLoginEndpoint!,
    clientId: config.clientId!,
  });

const baseURL: GraphEndpoint = config.graphEndpint as GraphEndpoint;
const authConfig: TeamsUserCredentialAuthConfig = {
  clientId: config.clientId,
  initiateLoginEndpoint: config.initiateLoginEndpoint,
};

const credential = new TeamsUserCredential(authConfig);
const provider = new TeamsFxProvider(credential, config.userScopes, baseURL);

Providers.globalProvider = provider;

  return (
    <TeamsFxContext.Provider value={{ theme, themeString, teamsUserCredential }}>
...

Upvotes: 0

Trinetra-MSFT
Trinetra-MSFT

Reputation: 1015

You send a POST request to the /token identity platform endpoint to acquire an access token:

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

Host: login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded

client_id={client_Id}
&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default
&client_secret={client_secret}
&grant_type=client_credentials

You will get access Token in response

{
  "token_type": "Bearer",
  "expires_in": 3599,
  "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik1uQ19WWmNBVGZNNXBP..."
}

Please take a look at Get access token

Upvotes: 6

Related Questions