Getting "URL Blocked" for Facebook login error on Rails 5 app - ruby-on-rails

I'm implementing Facebook login on a Rails 5 app with Devise and the omniauth-facebook gem and I'm getting the following error:
URL Blocked: This redirect failed because the redirect URI is not whitelisted in the app’s Client OAuth Settings. Make sure Client and Web OAuth Login are on and add all your app domains as Valid OAuth Redirect URIs.
I followed this tutorial: https://medium.com/#trydelight/facebook-authentication-with-devise-5b53d2f664ed
So for the "Valid OAuth Redirect URIs" it works locally with no URIs whitelisted, but for production I added
https://noora.app/users/auth/facebook and https://www.noora.app//users/auth/facebook (the production domain is noora.app). After getting the error I even added 2 more URIs with a / on the end and added noora.app and www.noora.app as domains, but I'm still getting the same error.
The app is on live mode and the login page is at https://noora.app/users/sign_in. Part of the Facebook settings are here:
Any ideas? Config seems good, but maybe someone sees something I don't? Thanks!

You should whitelist your callback url, not the one that has login button:
https://noora.app/users/auth/facebook/callback

I was looking for this answer for hours, the solution for me was:
When I checked the params in facebook error page, it said:
redirect=mydomain/auth/facebook/callback
and not:
redirect=mydomain/users/auth/facebook/callback
So I add the first one to Valid OAuth Redirect URIs, without users, and problem solved!!!

Related

linkedin oauth authorization fails with "Bummer, something went wrong"

Bummer, something went wrong
https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=test&redirect_uri=http://test.custom.com/abc/linkedin&state=DCEeFWf45A53sdfKef424asgTyhgTR5
when I use the above url I am getting "Bummer, something went wrong.
We're having difficulty connecting."
you need to add Sign In with LinkedIn permission in product tabs
from the app settings page go to the product tab and add Share on linkedin and Signin with linkedin to get the following permissions r_emailaddress, r_liteprofile, w_member_social
Hello I had a similar problem and I fixed it by doing this ;
You have to ensure that everything in your APP page ( https://www.linkedin.com/developer/apps ) matches the parameters in your authorization URL . SO for example in your case , https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=test&redirect_uri=http://test.custom.com/abc/linkedin&state=DCEeFWf45A53sdfKef424asgTyhgTR5 ;
You would have to ensure that your client_id in the auth URL matches the Client-Id on your APP page and also ensure that the redirect_uri you specified in your auth URL has been authorized on your app page as shown below . If you are passing in scopes as well, also ensure that they match perfectly . As you can see in the image below , my redirect_uri has been authorized from my app page .
Recreate a application after 12/15/2018 solved the problem for me.
(Any developer application created through the LinkedIn Developer Portal after December 15, 2018 automatically has access to the v2 API.) https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/migration-faq?context=linkedin/consumer/context
I ran into same issue.
Changing value of redirect_uri in linkedin app from http to https helped solved the issue. See picture below:
In your case, url should have been:
https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=test&redirect_uri=https://test.custom.com/abc/linkedin&state=DCEeFWf45A53sdfKef424asgTyhgTR5 ;
The best is to inspect how is the link generated by linkedin developer tool for you and then you just have to change the redirect url
https://www.linkedin.com/developers/tools/oauth
then "create token" then select all permission and click on "Request access token"
if you have the development window open you can see a query authorisation is done, then you can just copy this url and change the redirect_url.
]1
so for me
https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=myclientid&redirect_uri=myredirectid&scope=r_emailaddress%2Cr_liteprofile%2Cw_member_social&state=e6c0e1c8-1a35-478f-8eea-b0412a6675c9

Oauth2 redirect_uri_mismatch

I've setup an environment in Cloud9 to create a website in Rails. I'm currently trying to enable login via Gmail, using the google oauth2 gem, but i ran into this problem and no matter where i look, every solution i've found does not seem to work.
Here is the error:
(https://i.imgur.com/GhIH8S4.png)
And here is my google development urls:
(https://i.imgur.com/zg5Txuo.png)
(Sorry, seems like i can't upload images directly to the post yet)
I think you are having this issue because Google's OAuth does not support wildcard subdomain matching and your app is basically a subdomain on Cloud9. Check this SO post.
I found a post with similar issues on Cloud9 forums
I googled with "OAuth c9.io".
Have you added the authorized redirect URIs?. It´s in the Credentials tab. You must edit your OAuth 2.0 client IDs and set the URIs there.
Steps:
Go to https://console.developers.google.com/apis/dashboard
Select the project
Click on Credentials link on the left menu
Edit the OAuth 2.0 client IDs clicking the pencil next to it
Add your Authorized redirect URIs (https://domain/users/auth/google/callback or something similar)

LinkedIn OAuth 2.0 Redirect URL

I'm attempting to sign in users with the LinkedIn Omniauth 2 gem. I have tried a few different possibilities for the redirect, read several articles and nothing is working.
I'm trying to test this locally.
Rails 4 app
Gems include:
omniauth
omniauth-linkedin-oath2
A few attempts of the redirect URL to put in the box includ:
https://www.linkedin.com/uas/oauth2/authorization?client_id=759dczzx23nyic&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Flinkedin%2Fcallback&response_type=code&scope=r_basicprofile+r_emailaddress&state=8da572e31a8e66e6b1de54acddd14937d976ed06d7ed3217&client_id=*
= API Key that needs to stay private
http://localhost:3000
http://localhost:3000/
http://www.localhost:3000
https://localhost:3000
https://localhost:3000/
https://www.localhost:3000
I read both of these articles the entire way through, but still couldn't attempt to find the correct way to redirect it.
https://developer.linkedin.com/forum/register-your-oauth-2-redirect-urls
https://developer.linkedin.com/forum/oauth-20-redirect-url-faq-invalid-redirecturi-error
Any help in what I need to change would be great.
They need to match exactly what you are sending:
http://localhost:3000/auth/linkedin/callback
In case of Linkedin Authorized Redirect URLs should be in form of:
http://localhost:8080/your-project-name/auth/linkedin
After authentication if you want to redirect to a specific page then
http://localhost:8080/your-project-name/that-page-url
I was having a similar issue and kept getting "Invalid redirect_uri. This value must match a URL registered with the API Key." error when using Auth0
I added URL below to LinkedIn's list of allowed callback then it worked.
https://"Insert your Client Domain Name from Auth0"/login/callback

Oauth2 Instagram API "redirect URI does not match registered redirect URI"

I am working on a Rails application which is in development mode and it can register with omniauth.
The host is
http://localhost:3000/
I'm using the gems:
gem 'omniauth'
gem 'omniauth-foursquare'
gem 'omniauth-instagram'
When I register through omniauth with Foursquare there's no problem at all. All the settings are right and my redirect_uri in the Foursquare developer settings equals to the host (localhost:3000)
However, if I fill in the exact same redirect_uri (localhost:3000) in the Instagram client manager*. Instagram gives me this:
{
"code": 400,
"error_type": "OAuthException",
"error_message": "Redirect URI does not match registered redirect URI"
}
Based upon this URL:
https://instagram.com/oauth/authorize?response_type=code&client_id=<ID>&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Finstagram%2Fcallback&state=18415adf24dd97873e61094f67c0fb7a94857fedf93e9d2e&scope=basic
*
What am I doing wrong according to Instagram and how should this be fixed?
Fixed the issue myself. Added localhost:3000/auth/instagram/callback as redirect_uri and it worked just fine.
When you specify a redirect URI http://localhost:3000 is not the same as http://localhost:3000/ (note the trailing slash).
Make sure the callback URI matches exactly.
I needed to add
http://localhost:3000/users/auth/instagram/callback
as my callback URI because I'm using Devise.
For Drupagram module (Drupal 7) added: http://localhost:3000/instagram/oauth as redirect_uri
For anyone that is having this issue and the redirect uri provided to instagram is exactly the same as the one you're using, i've found that some users were typing my website address as http://www.example.com/login when in my instagram api it was http://example.com/login.
Then I created a php script to detect if the string www exists in my url and then reload to the same page but without the www.
if(strpos($_SERVER['HTTP_HOST'], 'www.') !== FALSE) {
header("Location: ".str_replace('www.', '', $_SERVER['HTTP_HOST'].'/'.$_SERVER['REQUEST_URI']));
}
Issue: Oauth2 Instagram API “redirect URI does not match registered redirect URI
My Solution: Please check ng-cordova-oauth.js file and check instagram function in that. Verify redirect_uri value is same as register your application on developer console for Instagram.If it is same it works properly,otherwise you get the above issue.
{"error_type": "OAuthException", "code": 400, "error_message": "Redirect URI does not match registered redirect URI"}
How to get Access token from instagram
Your website url must be same when registering sandbox clien api on instagram https://www.instagram.com/developer/
here we used website url: https://adlivetech.com
Valid redirect URIs: https://adlivetech.com/
For live website you can get Access token easily by using https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token
Replace above url "CLIENT-ID" with your client ID
Replace above url "REDIRECT-URI" redirect url should be your domain name like: http://adlivetech.com
https://adlivetech.com/access_token=YOUR_ACCESS_TOken
I mucked around with this for ages..
perhaps it has changed but:
http://localhost:3000/users/auth/instagram/int_callback
was the callback URI that finally worked for me.
The ONLY issue i was having was that it was exactly an incorrect callback uri and wish I had seen here that I should be focusing on my Instagram setup instead of modifying my code.. to get the error message means everything else is working (so far), otherwise you would not be getting that particular error message.
Good luck!! - don't get distracted!
This isn't a ruby-specific but for anyone else wrestling w/this here's what got me past it (note: nothing in above answers worked for me):
1. Edit your Client on Instagram Developer and uncheck Disable implicit OAuth.
2. Click Update Client to save it.
3. Now go to https://instagram.com/oauth/authorize/?client_id=[CLIENT_ID]&redirect_ur.... Just change [CLIENT_ID] and [REDIRECT_URI] with their values.
4. After that you will be redirected to [REDIRECT_URI]/#access_token=[ACCESS_TOKEN]. Get it and place it on the Instagram Access Token textbox.
(Source: https://www.drupal.org/project/instagram_feeds/issues/2140479)
...Or you can follow the instructions here:
https://instagram.com/developer/authentication/?hl=en
See "Step One: Direct your user to our authorization URL" section.
Just simply supply your CLIENT_ID and REDIRECT_URI.
https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code

Invalid redirect_uri with 'omniauth-facebook' gem

So I went to this guide that explains how to start with omniauth. When I got to the end of step 4 to test the application at localhost:3000/auth/facebook, I got this error:
{
"error": {
"message": "Invalid redirect_uri: Given URL is not allowed by the application configuration.",
"type": "OAuthException",
"code": 191
}
}
I understand the problem is the URL in the Facebook developer center, but none of the solutions I read works for me...
(I know that there are some questions before regarding this issue, but I'm new to Ruby on Rails and need an explanation for dummies.)
Defining these settings at the Facebook developer center solved this for me:
App Domain: (blank)
Site URL: http://localhost:3000
Check the website option and set the site URL to http://localhost:3000/.
If the Facebook user is being generated in your Ruby on Rails application as
http://localhost:3000/users/auth/facebook
you need configure the Facebook application (Website) under the App section to redirect to
http://localhost:3000/users/auth/facebook/callback
if you are in a production environment, something that i missed was just removing www. from the site url that you specify in the facebook app settings (settings > basic > Website with Facebook Login > site url).
so instead of http://www.website.com/ you should enter in http://website.com
this worked for me after a few hours of trying to figure out what was wrong and why i was getting this redirect erro.
If you already added a site url you must provide email and turn your app live, you can add email in settings -> basic -> contact email and then make your app live in APP REVIEW -> MAKE "you_app_name" PUBLIC? -> yes

Resources