Class CookieAccessTokenProvider
- Assembly
- Keycloak.AuthServices.Authorization.dll
IKeycloakAccessTokenProvider implementation for OIDC+Cookie Web Apps.
Retrieves the access token stored in the cookie authentication scheme when
SaveTokens = true is configured on the OpenIdConnect options.
public class CookieAccessTokenProvider : IKeycloakAccessTokenProvider
- Inheritance
-
CookieAccessTokenProvider
- Implements
- Inherited Members
Remarks
Register this provider instead of (or before) calling AddAuthorizationServer
when using AddKeycloakWebAppAuthentication:
services.AddCookieAccessTokenProvider();
services.AddKeycloakAuthorization().AddAuthorizationServer(...);
Ensure SaveTokens = true is set in your OIDC options so the token
is persisted in the cookie:
.AddKeycloakWebApp(config, configureOpenIdConnectOptions: o =>
{
o.SaveTokens = true;
o.ResponseType = OpenIdConnectResponseType.Code;
});
Constructors
CookieAccessTokenProvider(IHttpContextAccessor, ILogger<CookieAccessTokenProvider>, string, string)
Initializes a new instance of the CookieAccessTokenProvider class.
public CookieAccessTokenProvider(IHttpContextAccessor contextAccessor, ILogger<CookieAccessTokenProvider> logger, string cookieScheme = "Cookies", string tokenName = "access_token")
Parameters
contextAccessorIHttpContextAccessorThe HTTP context accessor.
loggerILogger<CookieAccessTokenProvider>The logger.
cookieSchemestringThe cookie authentication scheme where tokens are stored. Defaults to AuthenticationScheme ("Cookies").
tokenNamestringThe name of the token to retrieve. Defaults to
"access_token".
Properties
CookieScheme
Gets the cookie authentication scheme name used for token retrieval.
public string CookieScheme { get; }
Property Value
Methods
GetAccessTokenAsync(CancellationToken)
Gets the current access token.
public Task<string?> GetAccessTokenAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe cancellation token.