Python - Microsoft Access Token Request Error - 400 Bad Request - azure

I am trying to get access token from access code . but there is a error of 400 Bad Request error
I am using this link to get Access code
in response of this link i am getting the code in query string with return url
code=0.ARAAFJ0TJCzGR0yL3c5x6h1Qz0253KDx4QtFrMHVT2YmlaUQAOw.AgABAAIAAAD--DLA3VO7QrddgJg7WevrAgDs_wQA9P_v97FhMMeLPwetJQTyqiAGcGH58lwAo6A_ZZolSYosec92P2Jrub9QkWnd9YXe5CkT3TVaqdVS7L1a8HR24Cw0uvavTJLsUO6tWkEoH_R06KnA6C4ZAOJpmBm27DXwFTQ2UWwtUGuYc9aZ7lfOkaSYEsUBXUoA1NLrhOiyXoACciHT2rQrgP59BhjaRYDNuKjJE6JiQx91spNUuklVveyclvPvlZ9rTV6h_gpzsuyC1eEbSA_4dbQaNTOpNF2U3vzzkCo3xgJYmULiDVSGp7K2iub9bNZhbiiexb3XgSV8E04OUvQIKkGlnlnuCItazEt3EkMvCP7FunimfFaFlaf_2ezaMncHYpn4KaoR_R1dI_tesooq71goe3GcmbKFSAKr4WGthlc2OKj6vcHjUmkP9TaGeyros-gR1lpPd-QTdTpVf4Q8_v7rJd8E7SXhMz1k_w1c3Crmt-1owjj6eeLA4pMqch8PPotqffdepAdjg4HX9fPnJV6NNgZP7ofoPCu-j8YikqGBjv11Ynum0tzJr2F4TZa0CIPU1Do97JFWpsjE35XC2DQlY1wTQRFtGNNRu0h81fuweXTdnci1c2utcsZqG87jln3iF9H-JOdZAfi0wGHzwY7Qrv3dFPIbaVyZyit6NCGa7g2TSUwWm7Ci1UQbXRoAkR1mzOucGFCP4WKE2mQfNfgQEiQCkZD9PeXjzm7NkbU9Q7AuYo6-1phMdfiTrruopAVHWbM04sjxJJU0LR4q8zYCbrgfkjBLDhi0SWpVNwzk9Og-02F0DPMh-6vXcVqjDVhVjl1YKOJ6pSY_Yofh97KJNmuj3YpkW3Ve2Pv3FQITZJLCRW0v7xIf7hStCnJQ9Yyi7bLcGcYv2_KTvyMgQS327FEbmDJGVU6cc6Kn
i am using this code to get access token :
But it is giving : requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://login.microsoftonline.com/common/oauth2/v2.0/token

Related

AAD B2C returned "AADB2C90090: The provided JWE is not a valid 5 segment token." when calling token API

I am working a POC to verify the migration of our Signup & Signup flow to Azure AD B2C. I have successfully called the API authorize to get the access token and id token. Then I tried to call /token to refresh the token according to document , however I got the error message below.
AADB2C90090: The provided JWE is not a valid 5 segment token.\r\nCorrelation ID: ae943eb7-9290-4fd5-aeac-d56411d803c7\r\nTimestamp: 2022-10-26 07:13:40Z\r\n
Following is the url I used to get access token in Browser.
GET https://{tenant}.b2clogin.com/{tenant}.onmicrosoft.com/oauth2/v2.0/authorize?p=B2C_1_signupsignin1&client_id=7adbb5f8-17d2-4dfa-94cd-5ab1cbc9f425&nonce=defaultNonce&redirect_uri=https://jwt.ms&scope=openid offline_access&response_type=code+id_token&prompt=login
Following is the screenshot I used to call token API in Postman.
POST /{tenant}.onmicrosoft.com/B2C_1_signupsignin1/oauth2/v2.0/token HTTP/1.1
Host: {tenant}.b2clogin.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 1971
grant_type=authorization_code&client_id=7adbb5f8-17d2-4dfa-94cd-5ab1cbc9f425&code=eyJraWQiOiJjcGltY29yZV8wOTI1MjAxNSIsInZlciI6IjEuMCIsInppcCI6IkRlZmxhdGUiLCJzZXIiOiIxLjAifQ..n8murSwIYYseViQm.WluJ_gU8aUQd1PPadPik4ODSso4KpKAu8geA5NmAlkbieJPVZb30MJSHGOiUsrxfwu4BoV69bshD7URJeVNFzfqPsCjBhpYDyeL8x0uUZIJwDQ7DTiflw8A4LbYf-SzjluqbfSqDwQFGyQvKesgsrnZzyxg9AnLiL1NoBW27Kd3ZcX3i1BHKr8c--qOyxbz8DtUyIzkJGcOq79wIQZRnDCr1_xPo6EhzOi59TlEIfJhzR4qfgLm3tlgK8zDaUY5Zf3a89olfkmpvrjS84vsfDyyWM4UZe_6MpymNQFe-6Q-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2k5b05KQzZYWjRVSkFvS0N6dyJ9.RckgULrCBdXzw-7-VYgmB7k0Ghfg1jRMsJF8_1oxLbNXTOcZDe9grbJKcpWoesHp5L5_bVfAa1HQOFzMlmPwPPvM0a2yl1zT8UQzJ_a8W4EHkA4Ao3Xt3osbjoBhRh65Nu4fCVGHswPgxZNAR_N7jr4pR6Pf4PllmKpne-bw7onz_HjpT4ulyyq8jNZye3YokPZh0ha9LaV_19NiwfnVAR451lqfugKs2DWfseXbyGlOnjFCl_UHQDOxa1_ZUTmvF1JUgff2VAOmW2925RMQopzfDjCUEvwZMLr8pKTystErvUR6a8itRAKIFwbfEh3en8PqBun9T89-5qKmmN4NTQ&client_secret=h888Q~Jlg97L2ngl6GHpaKqS6FmkLygeTVY7Eb-h
I tried to search the error message but only get two discussion threads in Stackoverflow, however no useful info found.
https://stackoverflow.com/search?q=AADB2C90090%3A+The+provided+JWE+is+not+a+valid+5+segment+token.
I tried to reproduce the same in my environment and got the same error as below:
To generate the access token, ID token and code in the browser I used the below parameters:
GET https://Tenant.b2clogin.com/Tenant.onmicrosoft.com/B2C_1_testuserflow/oauth2/v2.0/authorize?
client_id=37cd7fca-ea8f-4300-XXXX-XXXXXXXXXX
&response_type=code+id_token
&redirect_uri=https://jwt.ms
&response_mode=fragment
&scope=openid
&state=12345
The error usually occurs if you pass invalid code value. To resolve the error, make sure to copy only the code value not with id token.
I am able to call /token to refresh the token successfully like below:

API post request for microsoft Access token working in Postman but getting 404 Error from APIM

I am requesting below endpoint url to get access token by passing client id, secret ,scope and grant type(x-www-form-urlencoded) and I can able to get the access token with Postman.
But When I'm requesting the same post request from APIM url, setting the below end point as backend url im getting 404 error.
Could you please suggest is there anything, we need to include in policies in APIM or any changes in the request ?
EndPoint url :
https://login.microsoftonline.com/***tenantID****/oauth2/v2.0/token
Error in APIM test result:
Apim POST request:

Getting an error when doing a POST {{url}}/auth request to generate JWT Token in Postman

Trying to generate the JWT access token after clicking "send". However the following error occurs:
Postman logs:
Environmental Variables:
The URL looks as to be in the correct format.
Any idea on how to fix this?

Google Auth Exchange Code , Referesh Token and Access Token

I am trying to get the refereh_token, access_token using Google Auth Exchange Code, went through the documentation but it doesn't work, I am using a react-google-login for Auth and getting the code in response and i am passing the code
https://accounts.google.com/o/oauth2/token but its giving error
{
"error": "invalid_grant",
"error_description": "Bad Request"
}
i have tried lots of ways
code=4%2FKxoYTS-jeq5-d6Lv7YvSz9ZrK0pJ_5lZsMExzNC1M0o&redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&client_id=407408718192.apps.googleusercontent.com&client_secret=************&scope=&grant_type=authorization_code
frontend is reactjs and backend is nodejs..
To get the ACCESS token using referesh token you have to call a api which will give you a new access token
call a POST APi https://www.googleapis.com/oauth2/v4/token
pass the body as x-www-form-urlencoded i.e
Header as
Content-Type : application/x-www-form-urlencoded
Body
client_secret : 'xxxxxxxxxxxxdxxxxxSSd'<YourClientSecret>
grant_type : refresh_token'
refresh_token : '1/DDPkddk514451xxxxxxxx' <YourRefreshToken>
client_id : 'xxxxxxxxxxxxxxx' <YourClientID>
for more reference you can read this https://developers.google.com/identity/protocols/OAuth2WebServer

error on sending skype BOT messges

I have obtained the access token via https://login.microsoftonline.com/common/oauth2/v2.0/token and with that token tried to send a message using this url https://apis.skype.com/v3/conversations/conversationId/activities/. But i am getting this error "401: The provided 'OAuth' ticket failed authentication.".
What could be the issue here

Resources