I made mvc .net core app, and in my app I net to authenticate with a google services for google sheet api. Locally, everything works well, but when I deploy the app to azure I got some error.
"The specified CGI application encountered an error and the server terminated the process."
The problem is with the authentication to the google sheet api because I need to store the json file in the current directory of the app, but something there it is not working. I tried to make a remote debugging from my vs 2017 but I cannot solve the problem. If I delete the part with the authentication to the google api everything works well. Any suggestion? Thanks.
public HomeController()
{
var directory = Directory.GetCurrentDirectory();
var pathForJson = Path.Combine(directory, "client_secret.json");
var credential = GetNormalCredential(scopes, pathForJson, "sheets.googleapis.com-dotnet-quickstart.json");
// _sheetsService = (SheetsService)GoogleSheetFactoryService.GetService("Sheet", applicationName, credential);
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json");
var configuration = builder.Build();
AzureUrl = configuration["AppConfiguration:AzureUrl"];
AzureUrlGet = configuration["AppConfiguration:AzureUrlGet"];
}
public UserCredential GetNormalCredential(string[] scopes, string clientJsonPathFile, string clientCombinePath)
{
UserCredential credential;
using (var stream =
new FileStream(clientJsonPathFile, FileMode.Open, FileAccess.Read))
{
string credPath = Directory.GetCurrentDirectory();
string secondPath = @".credentials\sheets.googleapis.com-dotnet-quickstart.json";
credPath = Path.Combine(credPath, secondPath);
Debug.WriteLine("Credential file saved to: " + credPath);
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
return credential;
}