Ich benutze VS2015, C#.Google Login funktioniert nicht nach Veröffentlichung
Ich habe ein Problem mit der Google-Anmeldung. Von meiner Debug-Konfiguration (localhost) funktioniert alles einwandfrei. Nach dem Veröffentlichen auf dem Server wird das Google-Anmeldefenster einfach nicht geöffnet. Und keine Ausnahme wird geworfen. Hier ist mein Code:
[AllowAnonymous]
public async Task LoginWithGoogle()
{
HttpRequest request = System.Web.HttpContext.Current.Request;
string redirectUri = ConfigurationReaderHelper.GetGoogleRedirectUri();
try
{
ClientSecrets secrets = new ClientSecrets
{
ClientId = "***",
ClientSecret = "***"
};
IEnumerable<string> scopes = new[] { PlusService.Scope.UserinfoEmail, PlusService.Scope.UserinfoProfile };
GoogleStorageCredentials storage = new GoogleStorageCredentials();
dsAuthorizationBroker.RedirectUri = redirectUri;
UserCredential credential = await dsAuthorizationBroker.AuthorizeAsync(secrets,
scopes, "", CancellationToken.None, storage);
}
catch(Exception ex)
{
throw ex;
}
}
//just getting value from applicationSettings - web.config
public static string GetGoogleRedirectUri()
{
#if DEBUG
return GetValueFromApplicationSettings("RedirectUriDEBUG");
#elif PRODUKCIJA
return GetValueFromApplicationSettings("RedirectUriSERVER");
#endif
}
Natürlich I Servers Adresse des Ursprungs uri hinzugefügt und auch an den autorisierten Redirect uri auf der Google-Konsole für Entwickler. (genau wie ich für den localhost). Ich verstehe nur nicht, was falsch ist, warum Login-Fenster nicht geöffnet werden?
EDIT:
Hinzufügen Klasse dsAuthorizationBroker (wurde von meinem ersten Beitrag fehlt - leider auf, dass man):
namespace Notes
{
public class dsAuthorizationBroker : GoogleWebAuthorizationBroker
{
public static string RedirectUri;
public static async Task<UserCredential> AuthorizeAsync(
ClientSecrets clientSecrets,
IEnumerable<string> scopes,
string user,
CancellationToken taskCancellationToken,
IDataStore dataStore = null)
{
var initializer = new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = clientSecrets,
};
return await AuthorizeAsyncCore(initializer, scopes, user,
taskCancellationToken, dataStore).ConfigureAwait(false);
}
private static async Task<UserCredential> AuthorizeAsyncCore(
GoogleAuthorizationCodeFlow.Initializer initializer,
IEnumerable<string> scopes,
string user,
CancellationToken taskCancellationToken,
IDataStore dataStore)
{
initializer.Scopes = scopes;
initializer.DataStore = dataStore ?? new FileDataStore(Folder);
var flow = new dsAuthorizationCodeFlow(initializer);
return await new AuthorizationCodeInstalledApp(flow,
new LocalServerCodeReceiver())
.AuthorizeAsync(user, taskCancellationToken).ConfigureAwait(false);
}
}
public class dsAuthorizationCodeFlow : GoogleAuthorizationCodeFlow
{
public dsAuthorizationCodeFlow(Initializer initializer)
: base(initializer) { }
public override AuthorizationCodeRequestUrl
CreateAuthorizationCodeRequest(string redirectUri)
{
return base.CreateAuthorizationCodeRequest(dsAuthorizationBroker.RedirectUri);
}
}
}
Legen Sie einige Debug-Anweisungen, um herauszufinden, was letzte Zeile ausgeführt wurde. Das wird helfen, die Ursache zu beseitigen. Ich vermute, es wird nicht richtig Wert von AppSettings –
Wenn Sie es auf virtuellen Computer veröffentlicht haben, als versuchen, die Fehler von Event Viewer zu sehen – Lakhtey
@JohnPeters - Ich habe Protokollierung hinzugefügt. Ich melde erfolgreich eine Zeile vor UserCredential credential = .... Umleitung uri (aus dem Protokoll) ist uri, die ich im Gegenzug URI auf Google-Konsole habe. – FrenkyB