Google Calendar authentication Access is denied using Client Id and ClientSecret

58 Views Asked by At

my scenario is simple: I have a Web App that accesses my Google calendar. This App works fine when I run it from my PC using Visual Studio, but it gives an error when I run it on the server.

I'm using Client ID and Client Secret (as seen in my code below) to validate my access to the calendar, and as I said on my PC it works.

I know this is a recurring topic, but I've looked at hundreds of posts about this issue and haven't been able to find anything that shows me what I'm doing wrong.

Many posts have a very old publication date and perhaps something has changed in the API version.

My URI is registered within the Google console in the Authorized JavaScript origins and Authorized redirect URIs section

I've seen several posts that say there are differences between running on a PC and running on a server, but the script that performs the validation is too simple (apart from the credentials it has 2 lines, see code below).

Considering that it runs on my PC, could someone (please) guide me on which points I should check to try to identify the error...?

By the way..the error is: Access is denied / Failed to launch browser with "https://accounts.google.com/o/oauth2/v2/auth?access_type=offline........... .

I've been stuck with this problem for over two weeks and so far with no prospect of a solution, I would be very grateful for any help.

My code...

Private Async Function GetCalendarService() As Tasks.Task(Of CalendarService)
    Dim credPath As String = Server.MapPath("~\token.json")

    Dim credential As UserCredential
    credential = Await GoogleWebAuthorizationBroker.AuthorizeAsync(New ClientSecrets With {
        .ClientId = "11111111111-hsgdhsgdhsgdhsgdhsgd208b2ta8a9dnba7ue.apps.googleusercontent.com",
        .ClientSecret = "VVVVVV-NNNNN6YYYYYYYYhuPrkoSOcIsigkZZZ"
                    }, Scopes, "user", CancellationToken.None, New FileDataStore(credPath))


    Return New CalendarService(New BaseClientService.Initializer() With {.HttpClientInitializer = credential})

End Function
1

There are 1 best solutions below

4
Linda Lawton - DaImTo On

You are using code designed for ain installed application. Like a desktop application.

GoogleWebAuthorizationBroker.AuthorizeAsync opens the consent screen on the machine the code runs on you can NOT use it on a web server.