Get Refresh Token from Google

Hello!!, this is my first topic…
I have an asp.net core 3.1 web application where there is the option to add events to the google calendar through its API. I use Auth0 to authenticate only through the Google account, where I give the permissions to add and read the calendar. It works fine, but when the Google access token expires, you have to exit and re-enter the application to generate a new token. I read the option to generate the refresh token including the parameter “access_type = offline” in the endpoint authorization, but I could not continue because I configured the application as the quickstart tutorial, and the truth is that I don’t know where in the code I have to add the “access_type = offline”. Any help is welcome. Thank you

Hi @gwettstein,

Welcome to the Community!

Have you already looked through this topic?

Hello, thanks for answering. In fact I have read it. It was the first thing I found and read when this problem came up. I follow the tutorial that Auth0 suggests with asp.net core 3.1 for login. So I don’t know how to implement what the post says, especially the part about adding the line: access_type: ‘offline’. I don’t know if I have to use auth0-spa-js or configure it in Startup.cs of my project. When the user opens the webapp link, the user is directed to the Auth0 (Universal Login) login and only the “Continue with Google” button appears. I hope I have been able to explain myself well. Thanks again.

@gwettstein,

Okay I think I understand. You need to add that param to the request, but don’t know how to do it with the Microsoft.AspNetCore.Authentication.OpenIdConnect library.

I found this SO question that is similar. Can you try the strategy they use?

Thanks for the link!, I’ll check it out. I’ll keep in touch… :smile:

1 Like

Let us know what ends up working for you!

1 Like

Ok, I’ve been working on the code and I think I got it:
The problem is that the Google consent page appears every time the user logs on. That seems impractical to me, and the user experience is bad (I think):

The code that works is:

//code omitted for brevity
   OnRedirectToIdentityProvider = (context) =>
      {                        
            //the scope for Google Calendar I get it from Permissions option in Dashboard Connections/Social/Google
            context.ProtocolMessage.Parameters.Add("access_type", "offline");
            context.ProtocolMessage.Parameters.Add("approval_prompt", "force");                        
            return Task.CompletedTask;
      },
//code omitted for brevity

I will continue working tomorrow…

So far, I couldn’t think the way to prevent the Google consent page showing up every time a user logs into the app. But the code works so I put it as the solution.

Thank you for following up! Cheers :beers: