Reputation: 11
I am working on a .net core project trying to connect to google sheets. While running on my localhost everything goes smoothly, when publishing the app through azure I am unable to connect receiving this error:
Failed to load resource: the server responded with a status of 502 (Bad Gateway)
Here is my code:
UserCredential credential;
using (var stream =
new FileStream("client_id_1.json", FileMode.Open, FileAccess.Read))
{
string credPath = "token.json";
credPath = Path.Combine(credPath, ".credentials/sheets.googleapis.com-dotnet-quickstart.json");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
Service = new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
The file "client_id_1.json" contains the following:
{
"web": {
"client_id": "...",
"project_id": "...",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_secret": "...",
"redirect_uris": [ "https://{{mySiteHomePage}}" ],
"javascript_origins": [ "https://{{mySite}}" ]
}
}
Is there anything I am missing? How can I fix this issue?
Upvotes: 1
Views: 300
Reputation: 117291
GoogleWebAuthorizationBroker.AuthorizeAsync is designed for installed applications it opens the authorization web browser on the current machine which is why it works running localhost. If you try and run that hosted its going to try and open the authorization web browser on the server which wont work.
The Google .net client library does support asp .net core authorization I dont know of any samples for it I haven't had time to write any personally you might have luck digging around in the source code some of the unit tests might help.
Upvotes: 1