jwt validation azure api management - azure-api-management

I have implemented a jwt validation for api request through azure api management but it is failing.
The policy is something like this.
<validate-jwt header-name="Autherization" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized. Access token is missing or invalid." require-scheme="Bearer ">
<openid-config url="https://myb2cdev.b2clogin.com/myb2cdev.onmicrosoft.com/v2.0/.well-known/openid-configuration?p=B2C_1ctest" />
<audiences>
<audience>169679ed8-61df-0695-4375-574c3287ee98</audience>
</audiences>
<issuers>
<issuer>https://myb2cdev.b2clogin.com/97a8e403-f111-4454-8561-0c2881aae4a/v2.0/</issuer>
</issuers>
</validate-jwt>
Authorization token contains Bearer string appended.
ex token: "Bearer auserasereadnasewrewrwerwete...."
Note: there is a space betweeb Bearer and actual token.
Can any body helps me how to fix this.
The response is always :
{statusCode":401,"message":"Unauthorized.Access token is missing or invalid"}
THanks,

Remove the require-scheme="Bearer " from the policy. It will still validate the Bearer token sent in the Authorization header as Authorization: Bearer xxxxx

Related

Send bearer + token in request header C++ builder?

I'm working with a C++ application in embarcadero RAD Studio.
I'm trying to access my swagger api https://camur3.treffo.se/api/swagger/index.html to fetch information using the RESTClient, RESTRequest and RESTResponse components.
Now the API is authorized with bearer + token. Right now i can get out the token:
So i've trying to do a new call to the api from another button
void __fastcall TForm7::B_NewRequestClick(TObject *Sender)
{
RESTClient1->BaseURL = "https://camur3.treffo.se/api/users/authenticate/access";
//Request header + token??
RESTRequest1->Execute();
}
But don't know how to send the token in next request..
Anyone who knows how to do this?
You need to put the token in an Authorization request header, eg:
RESTRequest1->Params->AddHeader(_D("Authorization"), _D("Bearer ") + token);
Or
RESTRequest1->AddParameter(_D("Authorization"), _D("Bearer ") + token, TRESTRequestParameterKind::pkHTTPHEADER);
Or
RESTRequest1->AddAuthParameter(_D("Authorization"), _D("Bearer ") + token, TRESTRequestParameterKind::pkHTTPHEADER);

how to make a correct HTTP request to BigQuery from google script

I am working in google script API trying to get a schema of a table from BiqQuery... not sure why it is so troublesome.
I am sending a request like this :
let url = 'https://bigquery.googleapis.com/bigquery/v2/projects/'+ projectId +'/datasets/'+ datasetId +'/tables/' +tableId;
var response = UrlFetchApp.fetch(url)
I am getting this response:
Exception: Request failed for https://bigquery.googleapis.com returned code 401. Truncated server response: { "error": { "code": 401, "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie ... (use muteHttpExceptions option to examine full response) (line 68, file "bigQuery")
I have been able to load data to bigQuery alright... not sure why this does not work. I have looked at the OAuth fields in manifest and the script does have access to bigQuery...
no success also when adding this to the options field of the UrlFetch request
var authHeader = 'Basic ' + Utilities.base64Encode(USERNAME + ':' + PASSWORD);
var options = {
headers: {Authorization: authHeader}
}
Use bearer tokens
The reason why the BigQuery API rejects your requests is that the endpoint requires one of the following scopes to be provided with the access token to work, and it is missing from the request:
https://www.googleapis.com/auth/bigquery
https://www.googleapis.com/auth/cloud-platform
https://www.googleapis.com/auth/bigquery.readonly
https://www.googleapis.com/auth/cloud-platform.read-only
The actual issue here is that the basic authorization scheme lacks info about any claims, only sending over correct credentials. Since you are requesting the endpoint directly with UrlFetch service, despite correctly specifying the scopes in the manifest, they will not be sent over.
ScriptApp service now provides an easy method to get a valid bearer token without using an OAuth 2.0 library or building the flow from scratch: getOAuthToken. Pass it to an Authorization header as bearer token, and you should be all set:
const token = ScriptApp.getOAuthToken();
const options = {
headers : {
Authorization : `Bearer ${token}`
}
};
Use Advanced Service
As an alternative, there is an official advanced service as a wrapper around BigQuery REST API that will manage authentication and response parsing for you.
You must enable the BigQuery advanced service before using it
Also, note that the advanced service identifier is configurable, so you have to reference the identifier you chose.
In your case, the service can be used as follows (assuming you used the default BigQuery identifier). There is also the 4th argument of type object that contains optional arguments (not shown here):
Bigquery.Tables.get("projectId","datasetId", "tableId");
The method chain above corresponds to tables.get method of the BigQuery API.

request Vimeo private video file as Pro account

I want request my private video file by using video id(my account is Pro). but I don't have a idea how to credential my account in request.
This is what i did!
GET https://api.vimeo.com/videos/{video_id}
body
{
"grant_type": "client_credentials"
}
header
"Authorization" : "bearer {access_token}"
"Accept" : "application/vnd.vimeo.user+json;version=3.0,application/vnd.vimeo.video+json;version=3.4"
"Content-Type" : "application/json"
and this is resposne about that..
{
"error": "Something strange occurred. Please contact the app owners.",
"link": null,
"developer_message": "No user credentials were provided.",
"error_code": 8003
}
You're generating a client_credentials token, which can only retrieve public data on Vimeo. Instead, you need to generate an authenticated token, either via the OAuth workflow or a Personal Access Token on the Vimeo Developer Site. More information here:
https://developer.vimeo.com/api/authentication#using-the-auth-code-grant-step-1
https://developer.vimeo.com/api/guides/start/#generate-access-token
Generate access_token from your account after adding NEW APP.
then pass access_token in the URL or as a parameter
e.g https://api.vimeo.com/videos?access_token=***********************&links=https://vimeo.com/29474908

how can i call HTTP callable cloud function from postman?

I want to know that can i call cloud function from postman software .When i'm calling CF from postman it always give me
"error": {
"status": "INVALID_ARGUMENT",
"message": "Bad Request"
}
In Postman make post request, header Content-Type should be application/json and then in raw make json in this format
{
"data": {
"text":"hi how are you",
"phoneNumbers":"+92123455679"
}
}
Using #Vaaljan's answer I was able to authenticate a GCP cloud function that I created using the HTTP trigger method with authentication required:
gcloud auth print-identity-token
Then added it to the request Authorization header:
Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6I ... bnRzLmdvb2dsZS5jb20i
In Postman:
Could possibly also be that the cloud function is protected and can be invoked by adding Authorization header with the identity token as the Bearer.
You get the identity token by running
gcloud auth print-identity-token

No refresh token

We are working on an interesting project with Asana API. We used the example in this link https://github.com/Asana/oauth-examples
Things work fine up to refresh token process. When we post refresh request, we get the below json. This json does not include refresh_token to reuse one hour later. Can you please let me know what to do?
response = RestClient.post "https://app.asana.com/-/oauth_token",
:grant_type => 'refresh_token',
:refresh_token => '0/61d875c01bbd97b0a0bd7b48ebc7a29b',
:client_id => '11111111111',
:client_secret => 'xxxxxxxxxxxxxx'
puts response.body
returns below
{
"access_token": "0/672d061b4b1357de257d7e598f571140",
"token_type": "bearer",
"expires_in": 3600,
"data": {
"id": 5165131262780,
"name": "xxxx",
"email": "xxx#xxx.com"
}
}
This confused me as well.
You continue to use the same refresh token to obtain your next access token. No new refresh token is issued.
As the docs state, refresh_token is there "If exchanging a code" - the token exchange endpoint only includes a refresh token when exchanging code for tokens, not when exchanging refresh token for new bearer token.
You only get back a new bearer token when making the request with a refresh token. The refresh token is long-lived - if it expires, you go back through the code exchange.