I am trying to get a Microsoft AAD access token using a Power Query:
let
url = "https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token",
body = "{ ""client_id"": ""<client_id>"", ""client_secret"": ""<client_secret>"", ""grant_type"": ""client_credentials"", ""scope"":""<scope>""}",
options = [Headers = [#"Content-Type"="application/x-www-form-urlencoded"], Content = Text.ToBinary(body)],
tokenResponse = Json.Document(Web.Contents(url,options)),
AccessToken = tokenResponse[access_token],
AccessTokenHeader = "Bearer " & AccessToken
in
AccessTokenHeader
I get the following error:
DataSource.Error: Fehler beim Abrufen von Inhalten von "https://login.microsoftonline.com/****************/oauth2/v2.0/token" (400) durch "Web.Contents": Bad Request
Need help please, can't find anything on the web.
Related
I am trying to query my cosmos db for documents and I am having trouble generating the correct authorization header, the example in the official documentation does not show querying.
I am trying it in Postman using Javascript by POST to this URI:
POST https://MyDatabase.documents.azure.com:443/dbs/MyContainer/colls/MyDocuments/docs
With these headers:
The authorization is generated like this:
var now = new Date().toUTCString();
pm.request.headers.upsert({key: "x-ms-date", value: now })
var verb = 'POST';
var resourceType = "docs";
var resourceLink = 'dbs/MyContainer/colls/MyCollection/docs';
var text = (verb || "").toLowerCase() + "\n" +
(resourceType || "").toLowerCase() + "\n" +
(resourceLink || "") + "\n" +
now.toLowerCase() + "\n" +
"" + "\n";
//Hash and Encode by using the masterkey.
var key = CryptoJS.enc.Base64.parse("MyMasterKey");
var signature = CryptoJS.HmacSHA256(text, key).toString(CryptoJS.enc.Base64);
var authToken = encodeURIComponent("type=master&ver=1.0&sig=" + signature);
pm.request.headers.upsert({key: "Authorization", value: authToken })
Here is the error I am getting:
{
"code": "Unauthorized",
"message": "The input authorization token can't serve the request. Please check that the expected payload is built as per the protocol, and check the key being used. Server used the following payload to sign: 'post\ndocs\ndbs/MyContainer/colls/MyCollection\nwed, 27 may 2020 19:34:41 gmt\n\n'\r\nActivityId: 724657c7-0532-4c5d-a7ff-c95900ef13cf, Microsoft.Azure.Documents.Common/2.11.0"
}
I am guessing my signature is created wrong, what is the correct format?
Our docs on our Authorization Header should have what you're looking for.
hope this is helpful.
A required fix for your scenario is that you have to remove "/docs" at the end of the resourceLink value -keep it in the request URL- and also if your containter was created using a partitionKey you have to add the following header:
'x-ms-documentdb-query-enablecrosspartition': true
While registering iOS device token in SNS i am getting an error
"error": "Internal Server Error",
"message": "Invalid parameter: Token Reason: iOS device tokens must be no more than 400 hexadecimal characters (Service: AmazonSNS;
Status Code: 400; Error Code: InvalidParameter; Request ID:
3ae35ad6-8381-53b0-bd99-0c3a6417ac16)"
Code i used
The following ways to ways are used to retrive the token in IOS13
let token : String = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
let token : String = deviceToken.reduce("") { $0 + String(format: "%02.2hhx", $1) };
The token worked in pusher, but failed to upload in AWS with the following error.
Eg token -
272e5ce85513abbf3f46fc19059b-b6af26c2c04f633bac8c5b2fd3d791e26ba0
I'm struggling with RestFB 2.0.
This is my simple code:
AccessToken accessToken =
new DefaultFacebookClient(Version.VERSION_2_11).obtainAppAccessToken(MY_APP_ID, MY_APP_SECRET);
FacebookClient fc = new DefaultFacebookClient(accessToken.getAccessToken(), Version.VERSION_2_11);
AccessToken extendedAccessToken = fc.obtainExtendedAccessToken(MY_APP_ID, MY_APP_SECRET);
But on line #3 I get this error:
Received Facebook error response of type OAuthException: No user access token specified (code 1, subcode null)
Where am I wrong?
{
"error": {
"message": "Unknown path components: /$PAGE_ID,
"type": "OAuthException",
"code": 2500
}
I got the error above after trying to fetch a page posts using C# Facebook SDK 7.0.6
Here is my Request.
var downloadPostsTask = fb.GetTaskAsync(#"/" + PageId + #"?fields=posts{type,description,name,full_picture,source,caption,link,status_type,message}", ctsToken);
and
var downloadPostsTask = fb.GetTaskAsync(PageId + #"?fields=posts{type,description,name,full_picture,source,caption,link,status_type,message}", ctsToken);
both are resulting same error
How to solve this problem? I tried to search but it doesn't work at all.
I solved the problem by explicitly specifying Graph API Version in the Facebook object
var fb = new FacebookClient
{
AccessToken = token,
IsSecureConnection = true,
Version = "v2.6"
};
I'm implementing the X-FACEBOOK-PLATFORM XMPP authentication in Objective C (but using mostly C++ code) and I am getting always a failure:
<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>
I have the the app registered and the Id and Secret are as follows:
FacebookId #"136973476410894"
FacebookSecret #"f6e269fe158b4a04d00ce8b311453ccd"
I retrieve the session Token with FBConnect asking for the privileges:
#"publish_stream" ,#"xmpp_login" , #"offline_access"
The Session token is called token in the code (see below)
And then the program asks for the authentication mechanism:
<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="X-FACEBOOK-PLATFORM"/>
Receiving the challenge: <challenge xmlns="urn:ietf:params:xml:ns:xmpp-sasl">dmVyc2lvbj0xJm1ldGhvZD1hdXRoLnhtcHBfbG9naW4mbm9uY2U9OTAzMTM5MjY2ODk3N0Q0ODMyNDQ2MDY1REMzMTE5RTc=</challenge>
Then the Facebook Auth body extracted from the challenge: version=1&method=auth.xmpp_login&nonce=9031392668977D4832446065DC3119E7.
key: version, value: 1.
key: method, value: auth.xmpp_login.
key: nonce, value: 9031392668977D4832446065DC3119E7.
token: "BAAB8k59ntg4BANNuTHAkjTZBk3pW8pZBD7jWIpZBt8cf65oAT4eDm9euloGCX9NzfF9HwKQxUdEQ15YfeFtkdZAHVpkjL0j4CF0lZCQeuNTBXrvkbtUXC"
APIkey: "136973476410894"
APISecret: "f6e269fe158b4a04d00ce8b311453ccd"
Using the code from below a response is built:
token = Session token from FB connect: (BAAB8k59ntg4BANNuTHAkjTZBk3pW8pZBD7jWIpZBt8cf65oAT4eDm9euloGCX9NzfF9HwKQxUdEQ15YfeFtkdZAHVpkjL0j4CF0lZCQeuNTBXrvkbtUXC)
APIkey = FacebookId (136973476410894);
APISecret = FacebookSecret (f6e269fe158b4a04d00ce8b311453ccd);
string call_id=[[NSString stringWithFormat:#"%0.0f", [[NSDate date] timeIntervalSince1970]] UTF8String];
string signature1 = "api_key=" + APIkey
+ "call_id=" + call_id
+ "method=auth.xmpp_login"
+ "nonce=" + nonce
+ "session_key=" + token
+ "v=1.0"
+ APISecret;
string md = MD5(signature1);
//std::transform(md.begin(), md.end(),md.begin(), ::tolower);
string response2 = "method=auth.xmpp_login&api_key=" + APIkey + "&session_key=" +token + "&call_id=" + call_id + "&sig=" + md + "&v=1.0&" + "nonce=" + nonce;
printf("++base64EncodedResponse response2: %s.\n", response2.c_str());
string response2Base64 = Base64::Encode(response2);
Built response: method=auth.xmpp_login&api_key=136973476410894&session_key=BAAB8k59ntg4BANNuTHAkjTZBk3pW8pZBD7jWIpZBt8cf65oAT4eDm9euloGCX9NzfF9HwKQxUdEQ15YfeFtkdZAHVpkjL0j4CF0lZCQeuNTBXrvkbtUXC&call_id=1321457495&sig=5f376192b2dd1f5f928f651a996ce757&v=1.0&nonce=9031392668977D4832446065DC3119E7
Stanza sent(response): <response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">bWV0aG9kPWF1dGgueG1wcF9sb2dpbiZhcGlfa2V5PTEzNjk3MzQ3NjQxMDg5NCZzZXNzaW9uX2tleT1CQUFCOGs1OW50ZzRCQU5OdVRIQWtqVFpCazNwVzhwWkJEN2pXSXBaQnQ4Y2Y2NW9BVDRlRG05ZXVsb0dDWDlOemZGOUh3S1F4VWRFUTE1WWZlRnRrZFpBSFZwa2pMMGo0Q0YwbFpDUWV1TlRCWHJ2a2J0VVhDJmNhbGxfaWQ9MTMyMTQ1NzQ5NSZzaWc9NWYzNzYxOTJiMmRkMWY1ZjkyOGY2NTFhOTk2Y2U3NTcmdj0xLjAmbm9uY2U9OTAzMTM5MjY2ODk3N0Q0ODMyNDQ2MDY1REMzMTE5RTc=</response>
And the server returns:
<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>
I don't know where the problem is, it looks right to me, but there is no way to authenticate. Does anybody knows if there is any way to debug with the server the reason for the failure? May it be that the App is not yet in the App Store?
If someone can help it would be very welcome!
Since no one responded and someone else can get tricked by this same error due to the fact that this code appears on some examples about Facebook Authentication- I will post the response myself.
Everything is almost ok, it only requires the tag session_key to be changed for access_token in the signature1 string and in the response2 string.