VS2015, C# kullanıyorum.Google login yayınlandıktan sonra çalışmıyor
Google oturum açma ile ilgili bir sorunum var. Hata ayıklama yapılandırmamdan (localhost) her şey iyi çalışıyor. Sunucuya yayınladıktan sonra, google giriş penceresi açılmıyor. Ve hiçbir istisna atılmaz.
[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
}
Ben kökenli uri ve ayrıca geliştiriciler için google konsolda yetkili yönlendirme uri için sunucunun adresini eklendi Tabii: İşte benim kodudur. (tıpkı localhost için yaptığım gibi). Yanlış olanı anlamadım, neden giriş pencereleri açılmıyor?
DÜZENLEME:
ekleme sınıf dsAuthorizationBroker (ilk mesajım eksikti - o birinde üzgün): eğer
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);
}
}
}
Son satırın gerçekleştirildiğini öğrenmek için bazı hata ayıklama bildirimleri koyun. Bu kök nedenini sıfırlamak için yardımcı olacaktır. AppSettings –
'dan uygun değer elde etmediğini tahmin ediyorum. Eğer sanal makineye yayınladıysanız, Olay Görüntüleyicisi – Lakhtey
@JohnPeters - hatalarını görmeye çalışıyorum. UserCredential kimlik bilgisi = .... yönlendirme işleminden önce bir satırın başarılı bir şekilde oturum açmasını istiyorum (günlüğünden) uri, google konsolunda URI karşılığında sahip olduğum uri. – FrenkyB