doorkeeper auth flow not working - ruby-on-rails

I am trying to perform the oauth2 flow as described by https://github.com/doorkeeper-gem/doorkeeper/wiki/Interacting-as-an-OAuth-client-with-Doorkeeper#writing-a-raw-oauth-client, but I get a 401 when
I try to retrieve the access token. Here is what I am doing
1) click the authorize button on the application as seen here
2) I authorize the application on the next screen and I'm given a url of the form chromiumapp.org/?code=eb775dba8811f605c672a0aac8472972eabaae87446ac957e2b71c57b0b10e6e
3) Given this code I perform
curl -XPOST http://localhost:3000/oauth/token -d '{
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET,
"redirect_uri": "https://galaiojniedmogfplghkjnmcfnlbpbpg.chromiumapp.org/",
"grant_type": "authorization_code",
"code": "eb775dba8811f605c672a0aac8472972eabaae87446ac957e2b71c57b0b10e6e"
}`
However this returns {"error":"invalid_request","error_description":"The request is missing a required parameter, includes an unsupported parameter value, or is otherwise malformed."}
Is there some part of the flow that I'm missing or is there something incorrect in the documentation?

I have updated the wiki I linked above, but incase others come across this question, per the rfc, the parameters on the token request must be form urlencoded.
curl -XPOST http://localhost:3000/oauth/token
-F "client_id=CLIENT_ID"
-F "client_secret=CLIENT_SECRET"
-F "redirect_uri=https://galaiojniedmogfplghkjnmcfnlbpbpg.chromiumapp.org/"
-F "grant_type=authorization_code"
-F "code=eb775dba8811f605c672a0aac8472972eabaae87446ac957e2b71c57b0b10e6e"

Related

Why am I getting authorization code is not in a recognised format?

Hello everyone I need help please. This is about Seatgeek Oauth request.
In Postman, entered the required fields to get access token.However I am getting this error below.
{
"status": 400,
"message": "Oauth code invalid",
"errors": [
{
"message": "Oauth code invalid",
"short_message": "Code invalid",
"verbose_message": "The authorization code provided was not in a recognized format.",
"hint_message": "Switch code verifier",
"category": null,
"parameter": null,
"code": 40322
}
],
"meta": {
"status": 400
}
}
Now let me add the endpoints I used
Base endpoint: https://api.seatgeek.com/2/oauth/access_token
Params: client_id = xxxxxxxxx
Params: scope = offline_access,read-user-first-name,read-user-email,read-user-phone,view-soundersfc-crm-id
Params:grant_type = authorization_code
Body:x-www-form-urlencoded:
client_secret = xxxxxxxxxxx
code = “ ”
The full url will be something like this : https://api.seatgeek.com/2/oauth/access_token?client_id=xxxxxxxxx&scope=offline_access,read-user-first-name,read-user-email,read-user-phone,view-soundersfc-crm-id&grant_type=authorization_code
Please help me identify this code error. Any help will be highly appreciated
here is the Seatgeek Oauth documentation.
https://partners.seatgeek.com/enterprise-client-integration/oauth
SeatGeek API OAuth documentation not accuracy. you need a little change a scope.
(just use offline_access)
#1 Using this URL from Browser
https://seatgeek.com/oauth2?scope=offline_access&client_id=MzA...zcy
#2 You can get the code in URL address of browser
It will return your registered redirect URL and code
Copy that code and call POST to get token by curl
#3 Get token
curl -X "POST" "https://api.seatgeek.com/2/oauth/access_token" \
-H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' \
--data-urlencode "code={received_code_from_#2}" \
--data-urlencode "client_id={your_client_id}" \
--data-urlencode "client_secret={your_client_secret}" \
--data-urlencode "grant_type=authorization_code"
Note #1
you can get the client id /secret from developer portal
Note #2
code is JWT format. The payload is this content.
I decoded from jwt.io

Create organizationalBrandingProperties

I'm trying to create Organizational branding via Graph API
Unfortunately it doesn't work as documented
curl --fail-with-body --silent --show-error --oauth2-bearer TOKEN -X PUT -H 'Content-Type: application/json' -d #- https://graph.microsoft.com/v1.0/organization/7c9674e7-ad41-482b-af13-fff7ba1c38f6/branding <<< '{
"backgroundColor":"#FFFF33",
"signInPageText":"Welcome",
"usernameHintText":"hint"
}'
{
'error': {
'code': 'Request_BadRequest',
'message': 'Specified HTTP method is not allowed for the request target.',
'innerError': {
'date': '2021-04-21T12:59:57',
'request-id': 'a5ce577c-d0a9-4888-9999-521d7ba452b1',
'client-request-id': 'a5ce577c-d0a9-4888-9999-521d7ba452b1'
}
}
neither PATCH works:
curl --fail-with-body --silent --show-error --oauth2-bearer TOKEN -X PATCH -H 'Content-Type: application/json' -d #- https://graph.microsoft.com/v1.0/organization/7c9674e7-ad41-482b-af13-fff7ba1c38f6/branding <<< '{
"backgroundColor":"#FFFF33",
"signInPageText":"Welcome",
"usernameHintText":"hint"
}'
{
"error": {
"code": "Request_ResourceNotFound",
"message": "Resource '7c9674e7-ad41-482b-af13-fff7ba1c38f6' does not exist or one of its queried reference-property objects are not present.",
"innerError": {
"date": "2021-04-21T13:07:43",
"request-id": "c2c7056b-0043-40cb-82b8-6d262f190005",
"client-request-id": "c2c7056b-0043-40cb-82b8-6d262f190005"
}
}
I tried opening an Azure support request but they told me
The AAD Developer queue is experiencing a very high number of requests.
Please expect a delay in the assignation as the cases are assigned considering case severity, time in queue, customer service level and business impact.
Since Azure support has proven to be useless yet again, maybe somebody here would be able to help me? :)
Based on my test, I have the same error when I use PUT method.
But PATCH works fine for me.
id should be the organization id or tenant id.
Please get the id first with
GET https://graph.microsoft.com/beta/organization/
Then use the id for PATCH method:
PATCH https://graph.microsoft.com/v1.0/organization/{id}/branding
Content-Type: application/json
Content-Language: en-US
{
"backgroundColor": "#FFFF33",
"signInPageText": "Welcome",
"usernameHintText": "hint"
}
Update:
Application token is not supported for this endpoint. See Permissions.
Microsoft support finally responded (after 2 months!) with
Application Permission are currently not supported on this
endpoint, meaning that you will need an on-behalf of user token with
Delegated permissions to use this endpoint.
Since your goal was to automate this process, one workaround that
sometimes is feasible is to have a dedicated user in your tenant to
perform those actions, and that will authenticate with ROPC flow. This
flow allows to directly send the credentials information (username and
password) and because of that does not require an UI or interaction.
There is currently a known issue regarding the GET and PATCH method for the branding endpoint that is already reported and the fix
is in progress. This issue will cause an 404 error mentioning that the
tenant resource is not found.
Issue seems to be with locale being used, If you wish to get/update
the default branding, can you please try to include an header with
Accept-language as 0 (shown in the below image), if you want to get
branding for any other locale, you’ll need to pass the valid ISO-639
locale.

calling activities:list fails on using parameter `mine=true` (Youtube Data API V3)

I have been trying to use the API to retrieve my activities but I'm receiving the following JSON error.
{
"error": {
"code": 403,
"message": "The request is not properly authorized.",
"errors": [
{
"message": "The request is not properly authorized.",
"domain": "youtube.activity",
"reason": "forbidden"
}
]
}
}
, although I use https://www.googleapis.com/youtube/v3/activities?mine=true&key={my_api_key}&part=contentDetails and I use OAuth2 client to get an access token which I use on calling the API.
I tried to use the samples but I'm receiving the same error.
Is this a bug or I'm doing something wrong?
More details
I use the given link in postman with the GET method and I put a valid access token in the token field with TYPE=OAuth2 and Prefix=Bearer
According to the official specification of the Activities.list API endpoint, for to be able to use its mine request parameter, you have to issue the call to the endpoint while passing to it proper credentials:
mine (boolean)
This parameter can only be used in a properly authorized request. Set this parameter's value to true to retrieve a feed of the authenticated user's activities.
Therefore, using an API key is not sufficient (neither is required when issuing a properly authorized request).
Do note that the JSON error response obtained from the API agrees entirely with the specification quoted above.
According to the official (programming language agnostic) procedure, for to obtain a valid fresh access token from the API, issue a simple curl instance as follows:
$ curl \
--data 'grant_type=refresh_token' \
--data-urlencode "client_id=$CLIENT_ID" \
--data-urlencode "client_secret=$CLIENT_SECRET" \
--data-urlencode "refresh_token=$REFRESH_TOKEN" \
https://oauth2.googleapis.com/token
Above, $CLIENT_ID and $CLIENT_SECRET are the values of the corresponding properties of your client secrets JSON file you've got from Google's developers console. The $REFRESH_TOKEN is your (long-lived) refresh token you've obtained upon running a successful OAuth2 authentication/authorization flow.
The output obtained from curl when successful would look like:
{
"access_token": "...",
"expires_in": 3599,
"scope": "...",
"token_type": "Bearer"
}
A call to the Activities.list endpoint as yours above using curl is immediate:
$ curl \
--header "Authorization: Bearer $ACCESS_TOKEN" \
'https://www.googleapis.com/youtube/v3/activities?mine=true&part=contentDetails&maxResults=25'
The parameter $ACCESS_TOKEN above is your freshly obtained valid access token; the output of curl would look like:
{
"kind": "youtube#activityListResponse",
"etag": "...",
"items": [
{
"kind": "youtube#activity",
"etag": "...",
"id": "...",
"contentDetails": {
...
}
},
...
],
"pageInfo": {
"totalResults": ...,
"resultsPerPage": 25
}
}
For to run the above curl commands on a Windows machine under CMD.exe -- assuming that you've substitued the $-variables yourself manually --, do replace the backslash character at the end of each line above with the caret character, ^. The percent character % should be doubled, i.e. should be replaced with %%, and the single quote characters ' should be replaced with double-quote characters ".

Youtube API V3, search , publishedAfter, invalidSearchFilter

I'm just trying to make a search over youtube for my own videos that publisher after X date
However when i use publishAfter parameter, it's giving invalidSearchFilter error even of i set type parameter as video.
Error description is like this:
The request contains an invalid combination of search filters and/or restrictions. Note that you must set the type parameter to video if you set either the forContentOwner or forMine parameters to true. You must also set the type parameter to video if you set a value for the eventType, videoCaption, videoCategoryId, videoDefinition, videoDimension, videoDuration, videoEmbeddable, videoLicense, videoSyndicated, or videoType parameters.
You can reproduce this error from: https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?part=snippet&forMine=true&publishedAfter=1970-01-01T00%253A00%253A00Z&type=video&_h=11& (after login via oauth 2.0)
Any idea what can i do in this situation?
I used the link that you provided. The problem is not the date. The problem is the conflicting search restrictions that you used. To make your search work, leave the "forMine" parameter empty so it doesn't conflict with your date filters and possibly the 'q' parameter as well. Do that and it will work.
Also, you have to specify the channelID to specify it's yours. Give it a try
I am trying to work on a task to retrieve all the videos from our own channel, my problem with using forMine filter was, I was passing channelId filter alongside forMine filter (which actually does not make sense, if I am saying to get my own data then I should not pass channel id explicitly, so I blame myself for that), which was returning as an error saying that Request contains an invalid argument.
Here is what my request was when it was causing the error:
curl --location -g --request GET 'https://youtube.googleapis.com/youtube/v3/search?part=snippet,id&channelId=[Channel ID]&forMine=true&order=date&type=video&key=[API KEY]&maxResults=25' \
--header 'Authorization: Bearer [ACCESS TOKEN]' \
--header 'Accept: application/json'
And this was the JSON return:
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"errors": [
{
"message": "Request contains an invalid argument.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}
As soon as I removed the channelId query parameter, the error went away.

Zabbix Web Scenario / 400

I am struggling with Zabbix Web Scenarios, I am trying to post to a url in the same way this curl does:
curl -XPOST xxxx -d' { "grant_type": "password", "username": "xxx", "password": "xxx", "client_id": "xxx", "client_secret": "xxx"}'
However, I get a 400 error when loading it into Web Scenarios, here is the setup I am using in Zabbix.
This for some reason gives me back a 400 error, whereas the above curl works fine and I get an authorisation. Does any one have any more experience with this that can offer a hand?
You are not posting a JSON, but a list of individual variables. Try using the JSON as-is.

Resources