Working an application requires Refresh Token from OIDC (keycloak) to get authorisation for accessing resources. But it seems like the RefreshToken that returned seems to be expired or leaking.
The issue is that I'm able to log into the application and calls the RefreshToken and pass into my sync gateway method but the response is always 401 invalid.
Not sure how to debug further. Or is there a way I can try to refreshing the RefreshToken.
See code below. [startup.cs]
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = "Cookies",
AutomaticAuthenticate = true,
ExpireTimeSpan = TimeSpan.FromMinutes(60)
});
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
var oidcOptions = new OpenIdConnectOptions
{
AuthenticationScheme = "oidc",
SignInScheme = "Cookies",
Authority = Configuration["keycloak:authority"],
RequireHttpsMetadata = bool.Parse(Configuration["keycloak:httpMetadata"]),
PostLogoutRedirectUri = Configuration["keycloak:logoutUri"],
ClientId = Configuration["keycloak:clientId"],
ClientSecret = Configuration["keycloak:clientSecret"],
ResponseType = OpenIdConnectResponseType.Code,
GetClaimsFromUserInfoEndpoint = true,
SaveTokens = true,
CallbackPath = "/signin-oidc",
};
oidcOptions.Scope.Clear();
oidcOptions.Scope.Add("openid");
app.UseOpenIdConnectAuthentication(oidcOptions);
Method calls the RefreshToken
[HttpGet("getRec/{id}")]
public async Task<object> GetFileById(string id)
{
var refreshToken = await HttpContext.Authentication.GetTokenAsync("refresh_token");
//var authenticateInfo = await HttpContext.Authentication.GetAuthenticateInfoAsync("oidc");
//var refreshToken = authenticateInfo.Properties.Items[".Token.refresh_token"];
var token = HttpContext.Authentication.GetAuthenticateInfoAsync("refresh_token");
var val = await AppBal.GetFileById(refreshToken, id);
return val.Properties["files"];
}