404 when calling Imgur OAuth2 API - oauth-2.0

First attempt at using the Imgur API for OAuth2 authentication. I have a Client ID and Client Secret from https://api.imgur.com/oauth2/addclient. The URL that is being called from my Vue application looks like:
https://api.imgur.com/oath2/authorize?client_id={CLIENT_ID}&response_type=token&state=test
...where {CLIENT_ID} is the Client ID obtained from the client registration. This doesn't work from my web app and also fails in Postman. I'm getting back a 404 which displays the page that reads, "Zoinks! You've taken a wrong turn."
Any advice is appreciated.

I had the same problem. For me the solution was to open my Vue application from the network address https://192.168.2.100:8080 instead of the local adress https://localhost:8080
Vue console picture
Imgur apparently doesn't accept requests from localhost. Consequently I also had to set the OAuth2 redirect url of my application registered in imgur to http://192.168.2.100:8080/...

Related

OAuth2 code to front-end from back-end not working

I've been trying to implement OAuth2 for Google Sign-in with Vue and Deno, these are the relevant endpoints / domains
Back-end: localhost:8182
Front-end: localhost:8080
This is the flow of my setup: on the Vue front-end I fetch an authorization URI from the back-end, I've created this authorization URI with http://localhost:8080 as a redirect URI. Once the user signs in I get directed back to the Vue front-end with the authorization code in the URL.
Now I want to turn my authorization code into an access token, so using JavaScript I fetch the code from the URL and forward it to the back-end verification endpoint http://localhost:8182/oauth/validate, but it returns this error:
Invalid authorization response: Redirect path should match configured
path, but got: /oauth/validate
I figure that it errors out since I had the redirect URI set to http://localhost:8080 but I'm trying to get the token from /oauth/validate, I've also included my Google Cloud Console authorized URIs.
How can I fix this? In another post I saw someone using the same logic (sending the code from the front-end to the back-end and awaiting the result). But I must be doing something wrong
Have you tried removing /oauth/validate? I have a similar case in my local application. Here is how the "Authorized redirect URIs" section looks like:

What is the correct Redirect URI for Single Page App (SPA) runs inside a web browser for Oauth2 Auth Code Flow?

Say a SPA hosted in spa.com is loaded by user in user.com and uses oauth2 server oauth2.com for authentication through auth code flow (optional with PKCE). after user authenticated, oauth2.com would send the auth code back to the web browser and instructs it to redirect to the "redirect URI" registered with the app. now since SPA runs entirely inside the web browser, which can be anywhere, what the redirect URI should the SPA sent to oauth2.com to start with?
http://localhost : suppose to be just for local testing
its own address (user.com) : will not work since it is not registered
spa.com : SPA runs entirely in browser, not connected to spa.com
i know #1 and #3 do work but can't figure out why (#3). please advise what is wrong or missing with my understanding. thanks in advance!
The redirect URI for an SPA is usually the public URL of the app itself, so in your case this will be a value similar to one of these. On a developer PC this might be a localhost URL but I would think of it as a deployed URL and try to use proper domain names:
https://myspa.com
https://myspa.com/myapp
The technique for an SPA is then to see if you are receiving a login response as part of the main page load. See the call to handleLoginResponse in this source file of mine.

How to create Redirect URL for an app using Google API? (OAuth client)

I need the following information for my app to work:
1) Client ID
2) Redirect URL
Setting up the app and creating an ID + secret code was easy. But I have no idea what to put as my redirect URL. I used localhost as my URL and I was able to sign into my google account but after I signed in I received Error: redirect_uri_mismatch
Screenshot
What can I do? How do I even create a redirect URL?
In the Developer Console credentials page (the one in your screenshot), add your redirect URI to the "Authorized redirect URIs" text field.
Ensure you're supplying the correct port and correct route your server is listening on too.
For example, in the Google API Console, the working redirect URI for me is
Your port and route all depend on your server setup (ie. look in your index.js if you're using Node). This working sample with port 5000 is from the example server code in the YouTube API NPM module readme.

Installed App Authentication and Authorization

When authenticating a user for my vc++/mfc installed app with a localhost redirect via /o/oauth2/auth I do not get a code back, the response is always in the form `
https://accounts.google.com/o/oauth2/approval?as=6c4bc9dd35d125cf&hl=en_GB&pageId=none&xsrfsign=APsBz4gAAAAAUcQpxtoKLUKgovAEs4EJ9rlbP-wBci36
this particular response was from the localhost redirect example on accounts/docs/OAuth2InstalledApp.
My localhost authentication request looks like this,
https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=myclientid&scope=https%3A%2F%2Fgdata.youtube.com&redirect_uri=http://localhost
All the examples and my own code work fine with a OOB redirect but I would prefer to use the localhost redirect and then read the code from the url, any help would be appreciated.
Authentication, login, and upload all now work fine, I use the oob redirect and scan the html title rather than using localhost and scanning the url.

Google OAuth 2 authorization - swapping code for token

I'm trying to implement Google OAuth 2 to get access to Google APIs. I follow this guide, using server-side scenario.
I have no problem with getting the code, server redirects to localhost (which is the only server allowed in redirect URIs for now).
To achieve this, I go to https://accounts.google.com/o/oauth2/auth?client_id=whatever.apps.googleusercontent.com&redirect_uri=http://localhost/&scope=https://www.google.com/m8/feeds/&response_type=code page.
Then, I tried using curl (as in guide) to test, if Google's server responds with access token. However, it seems to fail very hard. Only response I can get is {"error":"invalid_client"}. I'm sure I provide everything Google wants me to provide - code, client ID, client secret, redirect URI (localhost) and grant_type=authorization_code.
Whole curl command line is:
curl https://accounts.google.com/o/oauth2/token -d "code=<code>&client_id=whatever.apps.googleusercontent.com&client_secret=<won't tell!>&redirect_uri=http://localhost&grant_type=authorization_code"
Am I missing something? How can I exchange code for access token?
Did you urlencode your client secret and redirect url? That works for me.
Should be http%3A%2F%2Flocalhost instead of https://localhost.
I had the same error until I realized that I was trying to connect with a client ID which I created for iOS. So for me the solution was to create a new API key-secret pair on the API Console with the platform set to "other".
Now I'm getting other errors but that's another story. ;)
Happens when you use wrong Client secret. Make sure you are using correct Client secret from Google API console. I was using Email address since API console displays the information in the following order:
Client ID
Email address
Client secret

Resources