Google login not working after posting

I am using VS2015, C #.

I have a problem with my Google login. From my debug configuration (localhost) everything works fine. After publishing on the server, the google login window simply does not open. And no exception is thrown. Here is my 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 } 

Of course, I added the server address to the source uri, as well as the allowed uri redirection on the Google Developer Console. (just like I did for the local host). I just don’t understand what’s wrong, why the login window doesn’t open?

EDIT:

Adding the dsAuthorizationBroker class (not in my first post - sorry for that):

 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); } } } 
+8
c # google-plus google-login
source share
1 answer
 public static async Task<UserCredential> AuthorizeAsync 

This method is already declared in GoogleWebAuthorizationBroker, and therefore, if you plan to use this function to take precedence over the base implementation, you need to use a new keyword.

 public new static async Task<UserCredential> AuthorizeAsync 

This is why I assume that you are registering a line break before

 UserCredential credential = await dsAuthorizationBroker.AuthorizeAsync 

At this point, it invokes the base implementation.

Also, I usually prefer to use DotNetOpenAuth to interact with Google, and there are many simple role models, like here and here .. but if you really want to flip your own using Google Apis only then this is a better place to run

+3
source share

All Articles