Authorization error: "Something went wrong on our end. Sorry about that" - pinterest

Using this code in a browser to get the access code...
https://api.pinterest.com/oauth/?response_type=code&redirect_uri=https://example.com/redirect.htm&client_id=appid&scope=read_public,write_public&state=768uyFys
I got a dialog and when I pressed OK, then I got this error:
{"status": "failure", "code": 12, "data": "path: /oauth/\nparams:<dict_itemiterator object at 0x7f9735706710>\nAuthError(code=500, message='dial tcp 127.0.0.1:22000: connect: connection refused')", "message": "Something went wrong on our end. Sorry about that.", "endpoint_name": "oauth_connect"}

I also faced an issue like this. You can paste the URL on google browser and copy the redirect_url and add the same in the Pinterest app. Pinterest will call the redirect URL after hitting the API. You can add logs in your application where the redirect URL is hitting to verify the response.
https://api.pinterest.com/oauth/?state=9750187663&scope=read_public&client_id=abc&redirect_uri=https://9fa6caa3.ngrok.io/laravel/public/pinToken&response_type=code
You will get the result
array (
'state' => '9750187663',
'code' => '15a1bcfb012abc1',
)

Related

Change default Laravel "Server error" message

I've noticed that in production mode with my debug mode set to false that most of my functions that have a try/catch will return the Laravel default "Server error" message.
I've been trying to hunt this message down with little luck, how can I customise this generic message returned from functions within my Laravel app whilst debug is turned off?
If you're referring to a very generic HTTP 500 error, it's a blade file in the framework.
If you want to display your own error for 5XX errors and such, you can override them by creating a blade file with the name of the error you want to override. For example:
resources/views/errors/500.blade.php
{{ __('Uh oh. Something has gone wrong behind the scenes.');
Now when a 500 error is encountered, your blade error will be displayed rather than the default Laravel 500 error.
You can create files for the common errors too obviously.
Update
The default messages for HTTPExceptions in Laravel are provided by the Symfony Response class found in the Symfony\Component\HttpFoundation directory.
When it comes to providing error messages in APIs, most will send the default HTTP status code in the headers and then supply a human error message in the response body.
For your example you might do something like:
return response()->json([
'errors' => [
[
'status' => 500,
'title' => 'Internal server error',
'message' => 'A more detailed error message to show the end user'
],
]
], 500);
You would then be responsible for consuming the error response and showing the end user the human readable error rather than the default generic Internal server error.
You might find some of the JSON API examples useful.
In my case, my Model extends Authenticable.
I changed it to Model and imported Eloquence.

Accessing API layer

I am trying to access an api function, for example I want to access the login function, I get the following error:
"message": "An internal error occurred during your request!",
Looking in the log file, the following log is there:
ERROR 2017-10-09 17:01:37,296 [11 ]
nHandling.AbpApiExceptionFilterAttribute - Processing of the HTTP
request resulted in an exception. Please see the HTTP response
returned by the 'Response' property of this exception for details.
System.Web.Http.HttpResponseException: Processing of the HTTP request
resulted in an exception. Please see the HTTP response returned by the
'Response' property of this exception for details.
I am using Postman to test. My URL is https://localhost:44347/api/Account/Authenticate. My header has Context-Type as "application/json" and in my Body I have the loginModel formatted as
{
"tenancyName": "tenantname",
"userNameOrEmailAddress": "admin",
"password": "123qwe"
}
Am not sure how else to proceed on this. Any ideas please? I have swagger installed as well.
I am using MVC + AngularJS template. I have not changed anything, just the default project.
Appreciate the assistance.
I have tested with Fiddler and it works correctly.
Note: make sure you type Content-Type correctly, on the question you typed Context-Type
Make a POST request! You may be missing this.

Trying to stop Google Directory API push notifications with a client returns 404

Using the documentation at https://developers.google.com/admin-sdk/directory/v1/guides/push#creating-notification-channels I subscribed to a notification using something like:
service = build('admin', 'directory_v1', credentials=credentials)
watch_data = {
'id': str(uuid.uuid1()),
'type': 'web_hook',
'address': 'https://example.appspot.com/push/user',
'payload': True,
}
subscription = service.users().watch(domain=domain, event='update', body=watch_data).execute()
# 'subscription' is stored
I got a proper reply and everything seem fine to that point.
Until I try to stop the notification with the following code:
# 'subscription' is retrieved from the storage
service = build('admin', 'directory_v1', credentials=credentials)
stop_data = {
'id': subscription.id,
'resourceId': subscription.resource_id
}
request = service.channels().stop(body=stop_data)
request.execute()
This raises an 'HttpError' 404 exception:
Response: <HttpError 404 when requesting https://www.googleapis.com/admin/directory/v1/admin/directory_v1/channels/stop? returned "Not Found">
Interestingly, using the same parameters (known good 'id' and 'resourceId' from the same user), the API explorer gadget at https://developers.google.com/admin-sdk/directory/v1/reference/channels/stop fails in the same way.
I've also been unable to find this endpoint in the full blown API explorer.
I believe that the discovery somewhat misbehaves.
The URI built by the client is: 'https://www.googleapis.com/admin/directory/v1/admin/directory_v1/channels/stop'
whereas the documentation states it should be:
'https://www.googleapis.com/admin/directory/v1/channels/stop'.
Could this be a bug in the API?
I'll try to make a "manual" authenticated request ASAP to check this hypothesis.
Edit 2016-11-09:
Tried a manual request using the following code:
# 'subscription' is retrieved from the storage
stop_data = {
'id': subscription.id,
'resourceId': subscription.resource_id
}
http = httplib2.Http()
http = credentials.authorize(http)
url = 'https://www.googleapis.com/admin/directory/v1/channels/stop'
method = 'POST'
response, content = http.request(url, method, body=json.dumps(stop_data),
headers={'content-type': 'application/json'})
I still get a 404 as a result. So I guess that the problem is not the endpoint URI.
If someone from Google reads this, can you please look into it?
It's not super critical but I'd like to not have dangling notification subscriptions.
Edit 2 2016-11-09:
Thanks to #Mr.Rebot for pointing out the reports API bug report.
Upon closer inspection, the problem here is exactly the same.
Using the manual request code above but adjusting the URI with an underscore, I'm finally able to make a successful request (returns 204).
url = 'https://www.googleapis.com/admin/directory_v1/channels/stop'
So there's definitely a bug somewhere and the following documentation pages have the wrong endpoint URI:
https://developers.google.com/admin-sdk/directory/v1/guides/push#stopping-notifications
https://developers.google.com/admin-sdk/directory/v1/reference/channels/stop
Also found this related post: Google Admin SDK Channel Stop endpoint is broken in client libraries
To those that wonders in the Google Docs hell for the past two years, and counting.
The wrong/right URL is:
https://www.googleapis.com/admin/reports_v1/channels/stop
And the Scope to use this URL is:
https://www.googleapis.com/auth/admin.reports.audit.readonly
I hope this helps someone :)

Ruby POST call from server fails

I'm trying to make a spotify web manager with ruby, to make that I'm following the Authorization Guide.
My backend looks similar to the example made by the spotify's guys in this github. You can see mine here code here.
So the error I'm getting are 400 - Bad request or 415 - Unsupported media type.
At first I was using the net/http core library, but because maybe I was doing something wrong I've used Typhoeus and the result are the same.
This is the code is not working:
request = Typhoeus::Request.new("https://accounts.spotify.com/api/token",
method: :post,
body: {
grant_type: "authorization_code",
code: code,
redirect_uri: "http://localhost:5000/auth/spotify/callback"
},
headers: {
"Authorization": "Basic #{Base64.strict_encode64("#{settings.spotify_id}:#{settings.spotify_key}")}"
},
followlocation: true
)
logger.info request.inspect
request.on_complete do |response|
logger.info "[]" * 100
logger.info response
if response.success?
logger.info "SUCCESS"
elsif response.timed_out?
logger.info "TIMED OUT"
elsif response.code == 0
logger.info response.return_message
else
logger.info "HTTP request failed: #{response.code.to_s}"
redirect '/auth/failure'
end
end
request.run
Well, if someone of you have any idea of what is happenning, It would be helpful to know it.
Thanks in advance.
Edit
The string interpolation is is working properly, has been tested on console.
"Basic #{Base64.strict_encode64("#{settings.spotify_id}:#{settings.spotify_key}")}"
About the redirect_uri, must to work well, one thing because the guide is explained with localhost example, and second, the first request explained on the Authorization Guide is working properly, the problem happens when I'm trying to do the 4 step on that guide.
Are you sure that kind of string interpolation works? Did you look at the traffic in wireshark to see if it is working correctly? It looks suspicious cause you use double-quotes within double quotes and still expect it to work. If you don't wanna set up wireshark, have your app post the request text on the console. Furthermore, are you sure Spotify will allow redirect_uri's with localhost? Also, when do you get the 400, and when do you get the 415? This is important information, you can't just conflate them like that.
I've changed the Typhoeus gem for HTTParty, and now the error is becoming clearer.
The main thing here is not the 400 or the 415 error, is the message attached to this error. The error here is:
"error"=>"invalid_grant", "error_description"=>"Invalid authorization code"
So, It's my fault not to be aware of that, but was not clear the message, sometimes the fatigue and frustration makes you not seeing the obvious.
Now, just have to know why the auth. code is not valid.
Anyway thanks for the help.

:1 is being appended to my ajax requests with jQuery

I'm trying to access an external API from my website, and for some strange reason I am getting an ':1' appended to my ajax requests. Everything else seems to be right. BTW, I'm trying to access the Bing Images API using jQuery.
$.get('http://api.bing.net/json.aspx?callback=?',
{
AppId : <MYAPPID>,
Query : 'help',
Sources : 'Image'
},
imageResponseHandler,
'json'
);
I get this URL, which throws a syntax error in chrome console:
http://api.bing.net/json.aspx?callback=jsonp1329103936801&AppId<myappid>&Query=help&Sources=Image:1
The ':1' at the end brings up a 'not expecting token :' error. Where is it coming from? Removing the colon and pasting the url into my browsers gets me the json I want, but this seems to break before actually making the request.
Thanks,
Siegfried

Resources