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

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.

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

Related

Google Calendar Event Insert HTTP message format?

Google provides the HTTP message format for all the Oauth messages but nothing when it comes to the Calendar's API.
I suspect they want you to use one of their libraries -- but I don't use any of the languages associated with their libraries.
I'm using C++ and forming my own HTTP headers and message content.
Can anyone provide a standard HTTP format for Calendar-event-insert?
I know it must be in JSON construction.
The data I want to send is:
Calendar ID will be "primary"
Summary
Description
Start time
End Time
Based on oauth messages - I'm assuming the message may also have to contain:
ClientID
AccessToken
Scope
redirect_uri
I am looking for correct "Key" strings(case sensitive) and format.
Thanks in advance for any help.
You can do this all your self. The doucmentation is all there
Calendar event.insert
If all you want to do is see the HTTP request that is made by the api you can use If you use the event.Insert try me You can see the request it builds and test that its working
POST https://www.googleapis.com/calendar/v3/calendars/primary/events HTTP/1.1
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
Content-Type: application/json
{
"end": {
"date": "2020-01-01"
},
"start": {
"date": "2020-01-01"
},
"description": "test",
"summary": "test"
}
With a post body of events.resource
oauth
If you have your own C++ oauth library you can probably use that to get an access token. Once you have the access token you simply need to add a Authorization header to the post request above with a bearer token of the access token.
Sorry i cant help much with the code for c++ but i made my own library for .net 3.5 because it was not supported by googles .net client library, so i can tell you that its doable you just have to do it all yourself.
Google c++ library
There is a c++ library its just deprecated but that doesn't mean you cant dig around in their code for a bit of help in doing this Google apis cpp client

How do I extract the access_token from an http respnse in Microsoft Visual Studio Code?

This is what the http response will look like:
Http/1.1 200 OK
{
"access_token": "<token-value-here>",
"expires_in": 300,
"token_type": "Bearer"
}
I would like to get the token by making the request and getting the token, then make that token value a variable to use in my remaining API tests so I don't have to keep calling for a new one.
I would like to do this using Microsoft Visual Studio Code. Is this possible?

Skype Bot Rest API, 403 The bot is not allowed to perform the requested operation

So I used an account and message my skype bot.
Received Message: {"text":"test","type":"message","timestamp":"2017-11-15T21:52:10.379Z","id":"1510782730376","channelId":"skype","serviceUrl":"https://smba.trafficmanager.net/apis/","from":{"id":"29:1tJkKyeNp1o5xbMfK9hxF_U2s7huwsAKi4LMD0kOJbkg"},"conversation":{"id":"29:1tJkKyeNp1o5xbMfK9hxF_U2s7huwsAKi4LMD0kOJbkg"},"recipient":{"id":"28:8a75f591-62bf-422b-be6c-4b4b8bd1a576","name":"SKYPE_BOT"},"entities":[{"locale":"ru-RU","country":"RU","platform":"Windows","type":"clientInfo"}],"channelData":{"text":"test"}}
Sending 'POST' request to URL : https://smba.trafficmanager.net/apis/v3/conversations/29:1tJkKyeNp1o5xbMfK9hxF_U2s7huwsAKi4LMD0kOJbkg/activities/1510782730376
Post parameters : {"replyToId":"1510782730376","recipient":{"id":"29:1tJkKyeNp1o5xbMfK9hxF_U2s7huwsAKi4LMD0kOJbkg"},"from":{"name":"SKYPE_BOT","id":"28:8a75f591-62bf-422b-be6c-4b4b8bd1a576"},"text":"Hello, test","type":"message","locale":"ru","conversation":{"id":"29:1tJkKyeNp1o5xbMfK9hxF_U2s7huwsAKi4LMD0kOJbkg"}}
Response Code : 403 Response message: Forbidden
403 The bot is not allowed to perform the requested operation.
what i'm doing wrong?
To communicate with the Bot Connector service, you must specify an
access token in the Authorization header of each API request, using
this format:
Authorization: Bearer ACCESS_TOKEN
from: https://learn.microsoft.com/en-us/bot-framework/rest-api/bot-framework-rest-connector-authentication#bot-to-connector

How to develop test-automation using Postman when OAuth 2.0 authorization is required

I have an ASP.NET Web API 2 which is using OAuth 2.0 for authorization. And let's imagine I have a simple Web API method, like:
GET: http://host/api/profiles/user123 (requires OAuth 2.0 token)
So, with Postman, it is easy to test this Web API. I get an OAuth token for user123 from the Web API OAuthAuthorization method and then I use that token in the header of the HTTP request:
GET /api/profiles/user123 HTTP/1.1
Host: {host}
Authorization: Bearer {Token}
Content-Type: application/json
Cache-Control: no-cache
However, if I save my test and run it later (either by Postman itself or by Newman), the token will be expired at that time and it won't work.
How can I make Newman to get a new token automatically for user123 and use it in the HTTP request?
Note: I know how to use Postman's Authentication helpers to ask for a new token. But this scenario doesn't fit the test-automation. In test-automation, I want to remove any human interaction.
It's simple, get your access token at run time and save it into environment variable. Then use it in your next Get request.
In Get Token request, do this in Tests sections:
var body = JSON.parse(responseBody);
pm.environment.set('AccessToken', body.access_token);
In your main Get request, you can use the environment variable in Authorization header:
Authorization: Bearer {{AccessToken}}
Hope this helps.

Issue while generating access token using OAuth2 Service Accounts

We're having an issue in generating access token using OAuth2 Service Account for Google Apps marketplace users. The token generated here would be used in accessing Google APIs(Contacts, Calendar, Mail, Admin SDK APIs) and thus all the Google Integrations within our Services are failing. This has started failing abruptly from March 9th 8AM PST. Can you please consider this as high priority and let us know the reason for the issue or if we have missed something here. We are getting API response as
{ "error": "invalid_request" }
Please find the below sample request with all the headers and params for 2 sample requests for "https://www.googleapis.com/oauth2/v4/token"(as in documentation) and "https://accounts.google.com/o/oauth2/token" endpoints. Both result in a error message with responses { "error": "internal_failure", "error_description": "Invalid Value"} and { "error": "invalid_request" } respectively.
P.S: The service email address,private key files used for generating the below signature in the sample requests works if we use respective Google Client libraries. But we are making use of Google's REST APIs. We've created a sample application in Google APIs console for testing with new service account details and this results in the same exception.
URL:
https://www.googleapis.com/oauth2/v4/token
Headers:
Content-Type:application/x-www-form-urlencoded
BODY:
grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiJodHRwczovL3d3dy5nb29nbGVhcGlzLmNvbS9vYXV0aDIvdjQvdG9rZW4iLCJzdWIi
OiJqYWdzQHNvbHV0aW9udGVzdC5jb20iLCJzY29wZSI6Imh0dHBzOi8vbWFpbC5nb29nbGUuY29t
LyIsImlzcyI6IjQ2OTU3MTY1OTAxNUBkZXZlbG9wZXIuZ3NlcnZpY2VhY2NvdW50LmNvbSIsImV4
cCI6MTQ1NzU5NTkwMCwiaWF0IjoxNDU3NTkyMzAwfQ==.VrsqS0nYSUVZn_SwMi7UJEYLDqRcWLzPrF9o6av-t1IYZbRkTybEdcnwWeUfnYXl_F88gFTllmRg
LSTBahM5gqpZrEAaWrRiDEVTo6rcN3hWm7MHcmZbwgdJB8B0ObV0Ivp5aTdLC5HcqsOumJvYpDCF
SyGU8StSg9pDujERzOo=
Response:
code:400
{
"error": "internal_failure",
"error_description": "Invalid Value"
}
URL:
https://accounts.google.com/o/oauth2/token
Headers:
Content-Type:application/x-www-form-urlencoded
BODY:
grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiJodHRwczovL3d3dy5nb29nbGVhcGlzLmNvbS9vYXV0aDIvdjQvdG9rZW4iLCJzdWIi
OiJqYWdzQHNvbHV0aW9udGVzdC5jb20iLCJzY29wZSI6Imh0dHBzOi8vbWFpbC5nb29nbGUuY29t
LyIsImlzcyI6IjQ2OTU3MTY1OTAxNUBkZXZlbG9wZXIuZ3NlcnZpY2VhY2NvdW50LmNvbSIsImV4
cCI6MTQ1NzU5NTkwMCwiaWF0IjoxNDU3NTkyMzAwfQ==.VrsqS0nYSUVZn_SwMi7UJEYLDqRcWLzPrF9o6av-t1IYZbRkTybEdcnwWeUfnYXl_F88gFTllmRg
LSTBahM5gqpZrEAaWrRiDEVTo6rcN3hWm7MHcmZbwgdJB8B0ObV0Ivp5aTdLC5HcqsOumJvYpDCF
SyGU8StSg9pDujERzOo=
Response:
code:400
{
"error": "invalid_request"
}
EDIT:Sample request as in the documentation. This code was working for us for the past 2 years and suddenly it stopped working yesterday.
POST /oauth2/v4/token HTTP/1.1
Host: www.googleapis.com
Content-Type: application/x-www-form-urlencoded
grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI3NjEzMjY3OTgwNjktcjVtbGpsbG4xcmQ0bHJiaGc3NWVmZ2lncDM2bTc4ajVAZGV2ZWxvcGVyLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJzY29wZSI6Imh0dHBzOi8vd3d3Lmdvb2dsZWFwaXMuY29tL2F1dGgvcHJlZGljdGlvbiIsImF1ZCI6Imh0dHBzOi8vYWNjb3VudHMuZ29vZ2xlLmNvbS9vL29hdXRoMi90b2tlbiIsImV4cCI6MTMyODU3MzM4MSwiaWF0IjoxMzI4NTY5NzgxfQ.ixOUGehweEVX_UKXv5BbbwVEdcz6AYS-6uQV6fGorGKrHf3LIJnyREw9evE-gs2bmMaQI5_UbabvI4k-mQE4kBqtmSpTzxYBL1TCd7Kv5nTZoUC1CmwmWCFqT9RE6D7XSgPUh_jF1qskLa2w0rxMSjwruNKbysgRNctZPln7cqQ
It worked after changing the sun.misc.BASE64Encoder encoding part in my code for generating jwt token.
byte[] encode = BASE64Encoder.encode(data).replaceAll("\n", "").getBytes();
(or)
Change your BASE64Encoder encoding part while generating jwt token from sun.misc.BASE64Encoder to org.apache.commons.codec.binary.Base64 as
Base64 encoder = new Base64();
byte[] encode = encoder.encodeBase64(data);
Add comments if you anyone need any clarifications.
This solution was provided by Google.

Resources