How Get a 2 Legged Token Autodesk? - token

I need to get "Get a 2-Legged Token" verification for a read-only access to upload files entered by other users but I'm running into the following error:
{
"developerMessage": "The required parameter(s) client_id,client_secret,grant_type not present in the request",
"errorCode": "AUTH-008",
"more info": "https://forge.autodesk.com/en/docs/oauth/v2/developers_guide/error_handling/"
}
I followed exactly the example on the site changing just my "client id" and my "client secret":
https://forge.autodesk.com/en/docs/oauth/v1/tutorials/get-2-legged-token/
can anybody help me?

The single quote is wrong format in header of curl.
Try this format
curl --location --request POST 'https://developer.api.autodesk.com/authentication/v1/authenticate' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'client_id=your_client_id_xxx' \
-d 'client_secret=your_client_secret_xxx' \
-d 'grant_type=client_credentials' \
-D 'scope=data:read'
It will be return access token
I am using Postman for HTTP call.
It is more convenient

Related

Google Drive API - Invalid Credentials

I want to use a scripted approach (probably via) curl, to access some simple info from the drive api, like creation date. Essentially I want to script what I can do in their web interface: https://developers.google.com/drive/api/v3/reference/files/list.
I having been using a curl command that they expose in a query at the above link:
curl \
'https://www.googleapis.com/drive/v3/files?corpora=user&q=createdTime%20%3E%20%272021-11-23T12%3A00%3A00%27&key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
I have created an API key for this purpose (unrestricted for now). And used this app to generate an access token: https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&client_id=735795831119-kcpkamhiaojavqrt67mti7thcaa6ce87.apps.googleusercontent.com
But I have spent hours chasing my tail over the 401 Invalid Credentials error. Any help on getting a more specific error message, or better way to do this seemingly simple query would be appreciated. Thanks!
The result of the link below is an Authorization code.
https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&client_id=735795831119-kcpkamhiaojavqrt67mti7thcaa6ce87.apps.googleusercontent.com
You need to exchange it to https://accounts.google.com/o/oauth2/token to generate an Access Token:
curl \
--request POST \
--data "code=[Authentcation code from authorization link]&client_id=[Application Client Id]&client_secret=[Application Client Secret]&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code" \
https://accounts.google.com/o/oauth2/token
The result of the curl above is something like this:
{
"access_token": "access token here",
"expires_in": 3599,
"refresh_token": "refresh token here",
"scope": "https://www.googleapis.com/auth/drive",
"token_type": "Bearer"
}
Now you have the access token, you can paste it in the code below alongside with your API key.
curl \
'https://www.googleapis.com/drive/v3/files?corpora=user&q=createdTime%20%3E%20%272021-11-23T12%3A00%3A00%27&key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
Note:
Make sure you enable the Drive API in GCP
Application Client Id and Application Client Secret can be found after you created an OAuth 2.0 Client ID in GCP.
Reference:
DaImTo answer on How to connect to the Google Drive API using cURL.

Mendeley - can not search catalog anymore "client is not allowed"

Since last week, the catalog search on Mendeley API is giving me the following result:
{
"message": "Client ID <client_id> is not allowed",
"status": 403
}
I am using standard code in Python that worked before:
mendel = Mendeley(client_id=client_id, client_secret=client_secret)
auth = mendel.start_client_credentials_flow()
session = auth.authenticate()
print(session.catalog.search('Nitrogen dynamics', view='all').list(50).items)
And I have the same result using curl:
curl -X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-u client_id:client_secret \
-d "grant_type=client_credentials&scope=all" \
https://api.mendeley.com/oauth/token
curl -X GET "https://api.mendeley.com/search/catalog?access_token={access_token}"

Keycloak 11.0.0 generating token scope parameter invalid

I'm in the process of updating Keycloak straight from version 6.0.1 to 11.0.0, the db migration was successful and was able to login into admin console, however the token generation seems to be broken, I'm sending below curl to generate token
curl --location --request POST 'http://localhost:8480/auth/realms/test/protocol/openid-connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'username=testUser' \
--data-urlencode 'password=testPassword' \
--data-urlencode 'scope=testRole' \
--data-urlencode 'client_id=testService' \
--data-urlencode 'client_secret=testServiceSecret'
On sending above request Keycloak complains of Invalid Scopes: testRole, however I've verified the role and user role mappings are in place and this used to work well with Keycloak 6.0.1.
Just on side note, our clients are Full scoped, so it something that is causing issue? Or something else have got changed or is there a way to ignore invalid scopes altogether while generating token?

How to get token using Cloud Foundry api?

I'm trying to get token from Cloud Foundry. I'm getting token from cf oauth-token command but I try using curl its giving me an error:
{
"description": "Unknown request",
"error_code": "CF-NotFound",
"code": 10000
}
The Curl command I'm using:
curl 'https://<domian>/oauth/token' -X POST \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Accept: application/json
What am I doing wrong?
It depends on used flow. See doc: https://docs.cloudfoundry.org/api/uaa/version/4.31.0/index.html#authorization

Cloud Speech API error: RecognitionAudio not set

While trying to follow the [quick start] (https://cloud.google.com/speech/docs/getting-started) for cloud speed API, after execute the "curl" command in command prompt, error occurred depicted as below:
{
"error": {
"code": 400,
"message": "RecognitionAudio not set.",
"status": "INVALID_ARGUMENT"
}
}
Why the RecognitionAudio is not set in the API itself? The sync-request.json used is same as the one in the quick start:
{
"config": {
"encoding":"FLAC",
"sampleRateHertz": 16000,
"languageCode": "en-US",
"enableWordTimeOffsets": false
},
"audio": {
"uri":"gs://cloud-samples-tests/speech/brooklyn.flac"
}
}
I'm not sure exactly what you're doing wrong but I was able to use the request as-is from the documentation without issue.
Did you get an access token for a Google Cloud project that had the speech API enabled? The following command generates the access token that can be used as a Bearer:
gcloud auth application-default print-access-token
It was helpful for me to use put the following into a script file (req.sh)
curl -s -H "Content-Type: application/json" \
-H "Authorization: Bearer <output>" \
https://speech.googleapis.com/v1/speech:recognize \
-d #sync-request.json
I then just used the output from print-access-token with the script.
I had exactly the same problem and I solved it adding quotes in the -d value, like this:
curl -s -H "Content-Type: application/json" \
-H "Authorization: Bearer <your-access-token>" \
https://speech.googleapis.com/v1/speech:recognize \
-d "#sync-request.json"
I was getting this error because I was not running the command in the cli in the same directory as my sync-request.json file.
Once I changed directories, I used the command from the documentation with my access token, and it worked fine.
I had the same problem and it worked for me when I omitted the #sync- from the curl command. This command worked for me:
curl -s -H "Content-Type: application/json" \
-H "Authorization: Bearer " \
https://speech.googleapis.com/v1/speech:recognize \
-d #request.json
Not sure what the exact function is of #sync ?

Resources