Hi I am using Yii authclient for social media login purpose.Now, I am trying to login my site with using Google.
main.php
'google' => [
'class' => 'yii\authclient\clients\GoogleOAuth',
'clientId' => '****************',
'clientSecret' => '***************',
],
Whenever i am trying to login with Google it returns error code 400.
request details:
scope=profile email
response_type=code
redirect_uri=http://localhost/project/buyold/frontend/web/customer/account/auth?authclient=google
xoauth_displayname=My Application
client_id=***********************************
I don't know what's wrong in my code or app setting.
Please help me.
This error means you are using a redirect URL that does not match any of what you have added to the Credentials of your application in Google Developer Console.
If the Authorized redirect URIs section does not have the URL you are using it will return 400.
Check your Authorized redirect URIs, add yours if its not added and please note that I don't really recommend keeping the URL with this format, here is an example of how to configure your virtual host with Apache or Nginx
Related
Trying to set up an Authentication for my app, and all seemed to be working correctly, but when I tried testing it out I got this error message
Authorization Error
Error 400: redirect_uri_mismatch
The redirect URI in the request, http://localhost:3000/api/auth/callback/google, does not match the ones authorized for the OAuth client. To update the authorized redirect URIs, visit: https://console.developers.google.com/apis/credentials/oauthclient/${your_client_id}?project=${your_project_number}
Can you point me in the right direction to fixing this?
Error 400: redirect_uri_mismatch
Is a configuration issue. The redirect uri is used to return the authorization code to your application after the user has consented to your applications access to your data. You have created a web client credentials up on Google developer console.
What you need to do is go back there and add a Redirect uri of
http://localhost:3000/api/auth/callback/google
It must match exactly don't add any spaces at the end or anything.
If you have any issues i have a video which will show you exactly how to add it Google OAuth2: How the fix redirect_uri_mismatch error. Part 2 server sided web applications.
Seems like there's a mismatch with the Authorized redirect URIs. Are you sure you have entered the correct URIs? Redirect URI should be the URL that you'll be redirecting the user to after the login page or the base URL of your application Eg: https://localhost:8000
Also, make sure that you are using the correct Client ID and Client secret
Similar Questions
Google OAuth 2 authorization - Error: redirect_uri_mismatch
Correct redirect URI for Google API and OAuth 2.0
I have modified sample code that connects to OneDrive and allows user to upload/download images to OneDrive. I have deployed MVC5 app here. Below is key piece of javascript code
$(document).ready(function () {
var client_id = "61029bc2-373d-46d6-935b-ab34b325ef3a",
scope = ["wl.signin", "wl.basic", "wl.skydrive", "wl.skydrive_update"],
//redirect_uri = "http://localhost:61727/home/callback"; //when redirect_uri is configured as localhost everything works find
redirect_uri = "http://onedriveuploaddemo.azurewebsites.net/home/callback"; //When I deploy application to azure get error saying invalid redirect_uri
WL.Event.subscribe("auth.login", onLogin);
WL.Event.subscribe("auth.sessionChange", onSessionChange);
WL.init({ client_id: client_id, redirect_uri: redirect_uri, response_type: "token", scope: scope });
WL.ui({ name: "signin", element: "signin" });
});
Please see below configuration of app
When I configure 'redirect_uri' as local host i.e. (http://localhost:61727/home/callback). Application works as expected. When I click on login button it redirect me to windows live login screen, then I can enter my username/password and I am redirected back to 'redirect_url'
But trouble starts when I change 'redirect_uri' that is pointing to page thats hosted in azure. I have hosted the MVC app here . When I click on 'SignIn' button it opens up dialog and closes it immediately. I am not able to grab error message. But it seems to be an issue with 'redirect_uri'
Do I need to enable any setting in Azure in order to get this done?
Note: While configuring 'redirect_uri' I am changing it at both the places i.e. in MVC app and in 'Application Registration Portal' and both are identical.
Using Fiddler4, I was able to catch the error message, which is:
The provided value for the input parameter 'redirect_uri' is not valid. The scope 'wl.signin wl.basic wl.skydrive wl.skydrive_update' requires that the request must be sent over a secure connection using SSL.
Microsoft now requires that the redirect URI use SSL for all authentication redirects. Localhost is exempt, which is why it worked there. If you want to allow login using Microsoft Account, you need to have SSL support on your site.
Also: it looks like you are using the very old LiveSDK for JavaScript, which isn't recommended any more since it doesn't support the newer OneDrive API. While there isn't a OneDrive SDK for JavaScript, you may find the sample code in OneDrive-Explorer-JS helpful to handle authentication without using the LiveSDK code. In particular, odauth.js should do pretty much everything you need.
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.
I'm trying to set up a mirror API service for Google Glass. I turned on Mirror API in the google dashboard per the instructions in the glass developer website for Mirror API.
But when I go to create a Client ID for Oauth2, I get "Invalid web origin".
I'm putting in www.myserver.com/foldercreated, which exists in my server.
Use your url's domain name as Authorized JavaScript origins such as:
http://www.myserver.com
And your callback urls as Authorized redirect URI such as:
http://www.myserver.com/foldercreated
Don't forget to set http:// (or https://) prefix.
I created a Google OAuth 2.0 ClientID and secret in Google Developer console
After that I tested in Google OAuth playground (https://developers.google.com/oauthplayground).
and registered ClientID and secret already created above and applied to Google OAuth 2.0 playground setting menu.
Some people say that after creating ClientID/secret they need some time for testing. So after two days I tried to test in the same conditions but the error is same redirect_uri_mismatch.
How can I solve this?
As little as having a '/' at the end of your uri and not having the same '/' at the end in your code will throw it off.
Your site URL and the Authorized redirect URIs in developer console should be the exact match.
This kind of error occurs if one URL has www (http://www.example.com) and the other URL is non-www (http://example.com).
Other common URI mismatch are:
Using http:// in Authorized Redirect URIs and https:// as actual URL, or vice-versa
Using trailing slash (http://example.com/) in Authorized Redirect URIs and not using trailing slash (http://example.com) as actual URL, or vice-versa
Here is the step-by-step procedure (with screenshots) to update the Authorized redirect URIs in Google Developer Console (For those like me who found it difficult to get to that page).
Go to https://console.developers.google.com
Select your Project
Click on the menu icon
Click on API Manager menu
Click on Credentials menu. And under OAuth 2.0 Client IDs, you will find your client name. In my case, it is Web Client 1. Click on it and a popup will appear where you can edit Authorized Javascript Origin and Authorized redirect URIs.
Here is a Google article on creating project and client ID.
It should be a exact match what you have given in the console.developers.com.
In my case I missed the www in the url.
For eg: you have given http://www.google.com but in console.developers.com you gave http://google.com
It will still throw error. So it should be exact match.
The redirect URI (where the OAuth response is returned to) has to be registered in Google APIs console, and the error is indicating that you haven't done that, or haven't done it correctly.
Go to the console for your project and look under API Access. You should see your client ID & secret there, along with a list of redirect URIs. If the URI you want isn't listed, click edit settings and add the URI to the list.
I kept getting this same error until I realized that I needed to put "signin-google" at the end of the redirect setting in the Google API console, like this (ie, NOT http://www.example.org/api):
http://www.example.org/api/signin-google
(Magento 1.*) if You use inchoo Social Connect Magento extension then:
Set below url in your google app (OAuth 2.0 client IDs):
Authorized Redirect URIs: http://www.example.com/socialconnect/google/connect/
Authorized JavaScript Origins: http://www.example.com
Don’t forget to replace http://www.example.com with your domain
Please make sure that in your google-client-api, the value of credentials in these field are matched as what you got from Google API console:
$client->setClientId('xxx.apps.googleusercontent.com');
$client->setClientSecret('xxx');
$client->setRedirectUri('http://example.com/oauth2callback');
$client->setDeveloperKey('xx');
This could happen when the value of setRedirectUri is different from the one you set in Google API console.