Google Auth runs in Visual studio but hangs when deployed to IIS

I am working with the Google .Net client library. The way it works is when a user wants to authenticate to Google the library spawns a new webpage for the user to authenticate with.

System.Diagnostics.Process.Start(authorizationUrl);

My code using the library

credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
    GoogleClientSecrets.Load(stream).Secrets,
    scopes,
    userName,
    CancellationToken.None).Result;

If I run this locally via Visual studio it works fine. However if I try to deploy it just hangs. If run it using Visual studio using Local IIS. I get the following error.

System.Exception: CreateServiceAccountAnalyticsReportingFailed —>
System.AggregateException: One or more errors occurred. —>
System.ComponentModel.Win32Exception: Access is denied at
System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo
startInfo) at System.Diagnostics.Process.Start(ProcessStartInfo
startInfo) at
Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.d__6.MoveNext() in
C:Apiaryv1.22google-api-dotnet-clientSrcSupportGoogleApis.Auth.DotNet4OAuth2LocalServerCodeReceiver.cs:line
89 — End of stack trace from previous location where exception was
thrown — at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
Google.Apis.Auth.OAuth2.AuthorizationCodeInstalledApp.d__8.MoveNext()
in
C:Apiaryv1.22google-api-dotnet-clientSrcSupportGoogleApis.AuthOAuth2AuthorizationCodeInstalledApp.cs:line
77 — End of stack trace from previous location where exception was
thrown — at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__4.MoveNext()
in
C:Apiaryv1.22google-api-dotnet-clientSrcSupportGoogleApis.Auth.DotNet4OAuth2GoogleWebAuthorizationBroker.cs:line
134 — End of stack trace from previous location where exception was
thrown — at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__1.MoveNext()
in
C:Apiaryv1.22google-api-dotnet-clientSrcSupportGoogleApis.Auth.DotNet4OAuth2GoogleWebAuthorizationBroker.cs:line
60 — End of inner exception stack trace — at
System.Threading.Tasks.Task`1.GetResultCore(Boolean
waitCompletionNotification) at
WebApplication1.WebForm1.AuthenticateOauth(String clientSecretJson,
String userName) in C:UsersdaimtoDocumentsVisual Studio
2015ProjectsWebApplication1WebApplication1index.aspx.cs:line 69
— End of inner exception stack trace — at WebApplication1.WebForm1.AuthenticateOauth(String clientSecretJson,
String userName) in C:UsersdaimtoDocumentsVisual Studio
2015ProjectsWebApplication1WebApplication1index.aspx.cs:line 83 at
WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in
C:UsersdaimtoDocumentsVisual Studio
2015ProjectsWebApplication1WebApplication1index.aspx.cs:line 31
C:inetpubwwwrootApp_DataMyGoogleStorage

I am not a system admin type person I have very little understanding of IIS. My guess is that IIS doesn’t have the permissions to be able to spawn the process? This is just a guess. I have tried setting the application pool to use my own personal account, I have tried network system as well.

Links to the following issues on the Client library

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The library supports another way of authenticating for use with Web Apps.

using System;
using System.Web.Mvc;

using Google.Apis.Auth.OAuth2;
using Google.Apis.Auth.OAuth2.Flows;
using Google.Apis.Auth.OAuth2.Mvc;
using Google.Apis.Drive.v2;
using Google.Apis.Util.Store;

namespace Google.Apis.Sample.MVC4
{
    public class AppFlowMetadata : FlowMetadata
    {
        private static readonly IAuthorizationCodeFlow flow =
            new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
                {
                    ClientSecrets = new ClientSecrets
                    {
                        ClientId = "PUT_CLIENT_ID_HERE",
                        ClientSecret = "PUT_CLIENT_SECRET_HERE"
                    },
                    Scopes = new[] { DriveService.Scope.Drive },
                    DataStore = new FileDataStore("Drive.Api.Auth.Store")
                });

        public override string GetUserId(Controller controller)
        {
            // In this sample we use the session to store the user identifiers.
            // That's not the best practice, because you should have a logic to identify
            // a user. You might want to use "OpenID Connect".
            // You can read more about the protocol in the following link:
            // https://developers.google.com/accounts/docs/OAuth2Login.
            var user = controller.Session["user"];
            if (user == null)
            {
                user = Guid.NewGuid();
                controller.Session["user"] = user;
            }
            return user.ToString();

        }

        public override IAuthorizationCodeFlow Flow
        {
            get { return flow; }
        }
    }
}

Code stolen from Web applications (ASP.NET MVC)


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x