I am using the following code to authenticate to Google using the Google .Net client library.
public static void auth()
{
string clientId = "xxxxxx.apps.googleusercontent.com";
string clientSecret = "xxxxx";
string[] scopes = new string[] { "https://www.googleapis.com/auth/contacts.readonly" }; // view your basic profile info.
try
{
// Use the current Google .net client library to get the Oauth2 stuff.
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret }
, scopes
, "test"
, CancellationToken.None
, new FileDataStore("test")).Result;
// Translate the Oauth permissions to something the old client libray can read
OAuth2Parameters parameters = new OAuth2Parameters();
parameters.AccessToken = credential.Token.AccessToken;
parameters.RefreshToken = credential.Token.RefreshToken;
RunContactsSample(parameters);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
I am using my own client id and client secret key.
This code is perfectly working when I am running from visual studio, but is not working from after hosted in IIS.
And I mentioned redirected URI in google api console is
http://localhost/authorize/
My IIS host Url is
http://localhost/googleintegration.aspx
I am facing this issue by last one month, can anyone please give a solution for this..
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…