You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use the Google.Apis.Auth.AspNetCore3 NuGet package, but I can't figure out how to configure it to store the tokens it receives. The documentation mentions the interface IDataStore for doing just that, but where do I pass its implementation?
The default behavior seems to be just storing the tokens in the Authentication Properties, but these aren't persisted so I lose the tokens across user sessions.
The text was updated successfully, but these errors were encountered:
GurGaller
changed the title
[Question] How to persiste refresh tokens in ASP.NET Core 3?
[Question] How to persist refresh tokens in ASP.NET Core 3?
Mar 30, 2021
The documentation you linked and IDataStore are relevant for installed applications, credentials are stored in IDataStore locally.
For web applications using Google.Apis.Auth.AspNetCore*, the credentials (i.e. the tokens) will be stored in ASP.NET Core authentication cookies (most likely, definetely if you are following this documention), so you need the cookies themselves to persist beyond sessions to achieve what you want. Take a look at Microsofot's docs on persitent authentication cookies.
Again, if you are following the example here you can achieve persistent authentication cookies as follows:
services.AddAuthentication(o =>
{
// This is for challenges to go directly to the Google OpenID Handler, so there's no
// need to add an AccountController that emits challenges for Login.
o.DefaultChallengeScheme = GoogleOpenIdConnectDefaults.AuthenticationScheme;
// This is for forbids to go directly to the Google OpenID Handler, which checks if
// extra scopes are required and does automatic incremental auth.
o.DefaultForbidScheme = GoogleOpenIdConnectDefaults.AuthenticationScheme;
o.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(options => options.Cookie.Expiration = TimeSpan.FromDays(10))
.AddGoogleOpenIdConnect(options =>
{
var clientInfo = (ClientInfo)services.First(x => x.ServiceType == typeof(ClientInfo)).ImplementationInstance;
options.ClientId = clientInfo.ClientId;
options.Events.OnRedirectToIdentityProvider = ctx =>
{
ctx.Properties.IsPersistent = true;
return Task.CompletedTask;
};
});
I'm trying to use the
Google.Apis.Auth.AspNetCore3
NuGet package, but I can't figure out how to configure it to store the tokens it receives. The documentation mentions the interfaceIDataStore
for doing just that, but where do I pass its implementation?The default behavior seems to be just storing the tokens in the Authentication Properties, but these aren't persisted so I lose the tokens across user sessions.
The text was updated successfully, but these errors were encountered: