Google API удостоверяване - грешка redirect_uri_mismatch

Опитвам се да удостоверя уеб приложението си с API на Google Plus. В конзолата за разработчици на Google под Идентификационни данни за моя Cliend Id for Web Application.

Добавям следния uri адрес за пренасочване: http://localhost:50883/oauth/add_oauth_token

Когато стартирам приложението си, получавам следната грешка:

400. That’s an error.

Error: redirect_uri_mismatch

Application: SID3

You can email the developer of this application at: [email protected]

The redirect URI in the request: http://localhost:55404/authorize/ did not match a registered   redirect URI.

Learn more

Request Details
from_login=1
response_type=code
scope=https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email    https://www.googleapis.com/auth/userinfo.profile
access_type=offline
redirect_uri=http://localhost:55404/authorize/
as=-45fed094242eac62
pli=1
client_id=389029010035-knoo3a2445r77pirc06h8fhgdc5q0dsv.apps.googleusercontent.com
authuser=0
hl=es

Така че по някаква причина Google променя моя uri за пренасочване към порт 55404, защо?. Благодаря много и поздрави

Това е кодът:

protected void LoginToGooglePlus(object sender, ImageClickEventArgs e)
    {

        PlusService service = null;
        UserCredential credential = null;

            string[] scopes = new string[] {PlusService.Scope.PlusLogin, PlusService.Scope.UserinfoEmail,
 PlusService.Scope.UserinfoProfile};
            // here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
           try
        {
            // here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
            UserCredential credentials;
            using (var stream = new FileStream("C:\\Users\\Usuario\\Documents\\Visual Studio 2010\\Projects\\WebApplication1\\WebApplication1\\client_secret.json", FileMode.Open, FileAccess.Read))
            {

                credentials= GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets, scopes, Environment.UserName, CancellationToken.None, new FileDataStore("WebApplication1")).Result;
            }
        }
        catch (Exception ex)
        {
            //If the user hits cancel you wont get access.
            if (ex.InnerException.Message.IndexOf("access_denied") != -1)
            {
                Console.WriteLine("User declined access");
                Console.ReadLine();
                return;
            }
            else
            {
                Console.WriteLine("Unknown Authentication Error:" + ex.Message);
                Console.ReadLine();
                return;
            }
        }

        // Now we create a Google service. All of our requests will be run though this.
        service = new PlusService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "SID3",
        });




}

JSON файлът, който използвам, е този:

{"web":{"auth_uri":"https://accounts.google.com/o/oauth2/auth","client_secret":"jpkVDaaMjlLCHGh67DJ9Zv19","token_uri":"https://accounts.google.com/o/oauth2/token","client_email":"389029010035-knoo3a2445r77pirc06h8fhgdc5q0dsv@developer.gserviceaccount.com","redirect_uris":["http://localhost:50880/Paneles.aspx"],"client_x509_cert_url":"https://www.googleapis.com/robot/v1/metadata/x509/389029010035-knoo3a2445r77pirc06h8fhgdc5q0dsv@developer.gserviceaccount.com","client_id":"389029010035-knoo3a2445r77pirc06h8fhgdc5q0dsv.apps.googleusercontent.com","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs"}}

person zoit    schedule 26.11.2014    source източник
comment
Не мисля, че Google променя порта ви, мисля, че сесията ви за отстраняване на грешки в asp променя порта ви. msdn.microsoft.com/en-us/library /ms178109(v=vs.100).aspx Uri адреса за пренасочване трябва да е същият като този, към който се обаждате.   -  person DaImTo    schedule 26.11.2014
comment
Здравей, Линда, поставих го на статичен порт и нищо, не работи, така че не знам какво да правя. Благодаря   -  person zoit    schedule 26.11.2014
comment
ще трябва да публикувате кода си мисля. и опитайте да добавите пълния файл към uri за пренасочване localhost:50883/oauth/add_oauth_token/test.aspx   -  person DaImTo    schedule 26.11.2014


Отговори (2)


Току-що реших същия проблем, просто като промених DataStore на null.

credentials= GoogleWebAuthorizationBroker.AuthorizeAsync(
    GoogleClientSecrets.Load(stream).Secrets,
    scopes,
    Environment.UserName,
    CancellationToken.None,
    null // <-- here
    ).Result;

Не знам защо, но спира произволните измамни пристанища. Трябва също да добавя, че в моя случай то просто реши един проблем, тъй като трябваше да публикувам приложението си онлайн, където това решение беше просто грешно. Ако някой има нужда от онлайн версията (asp.net 4.5 MVC 5), можете да използвате кода тук.

person Shiran Dror    schedule 23.01.2016

URL адресът за пренасочване на API и URL адресът за пренасочване на вашето приложение трябва да са еднакви.... Например (ако URL адресът на приложението ви харесва този localhost:55404/authorize/ и трябва да добавите същия URL в URL адрес за пренасочване на API localhost:55404/authorize/ )

person Charles    schedule 30.11.2014
comment
Имам същия проблем с помощта на Google Calendar API v3 и това не е решение, тъй като IIS винаги променя порта. - person Cheshire Cat; 11.03.2015