public class CustomTokenExtension : AbpOpenIdDictControllerBase, ITokenExtensionGrant
{
public const string ExtensionGrantName = "auto_token";
public string Name => ExtensionGrantName;
public async Task<IActionResult> HandleAsync(ExtensionGrantContext context)
{
var signInManager = context.HttpContext.RequestServices.GetRequiredService<AbpSignInManager>();
// var principal = (await HttpContext.AuthenticateAsync(OpenIddictServerAspNetCoreDefaults.AuthenticationScheme)).Principal;
// principal = await AbpClaimsPrincipalFactory.CreateDynamicAsync(principal);
var uid = context.Request.GetParameter("u").ToString();
if (string.IsNullOrEmpty(uid))
{
return new ForbidResult(
new[] { OpenIddictServerAspNetCoreDefaults.AuthenticationScheme },
properties: new AuthenticationProperties(new Dictionary<string, string>
{
[OpenIddictServerAspNetCoreConstants.Properties.Error] = OpenIddictConstants.Errors.InvalidRequest
}!));
}
if (!Guid.TryParse(uid, out var userId))
{
return new ForbidResult(
new[] { OpenIddictServerAspNetCoreDefaults.AuthenticationScheme },
properties: new AuthenticationProperties(new Dictionary<string, string>
{
[OpenIddictServerAspNetCoreConstants.Properties.Error] = OpenIddictConstants.Errors.InvalidRequest
}!));
}
// var userId = principal.FindUserId();
var userManager = context.HttpContext.RequestServices.GetRequiredService<IdentityUserManager>();
var user = await userManager.GetByIdAsync(userId);
var userClaimsPrincipalFactory = context.HttpContext.RequestServices.GetRequiredService<IUserClaimsPrincipalFactory<Volo.Abp.Identity.IdentityUser>>();
var principal = await signInManager.CreateUserPrincipalAsync(user);
await signInManager.SignInAsync(user, isPersistent: false);
//For abp version >= 7.3
await context.HttpContext.RequestServices.GetRequiredService<AbpOpenIddictClaimsPrincipalManager>().HandleAsync(context.Request, principal);
return new Microsoft.AspNetCore.Mvc.SignInResult(OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, principal);
}
but the granted scope and refresh token? how do i get those
Hi, yup i noticed i used a custom grant type, however if i want it to be same as code flow by using this custom grant type with passwordless, is it able to do it?
i mean, anyway that able to set to the local storage by calling the connect/token api with custom grant type?
We had an MVC AuthServer and a seperate web in Angular. Is there any possible that after calling an api, and we do a passwordless login, able to set the local storage just like this?
Attached with previous question regarding passwordless login
hi ya, i already clear redis and rerun, but still having same issue.
here are the logs from authserver.
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7378320Z level=info msg="Request starting HTTP/1.1 POST https://localhost:44322/connect/token - application/x-www-form-urlencoded 89"
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7396240Z level=debug msg="The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessRequestContext was successfully processed by OpenIddict.Validation.AspNetCore.OpenIddictValidationAspNetCoreHandlers+ResolveRequestUri."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7397580Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ProcessRequestContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+ResolveRequestUri."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7398460Z level=info msg="The request URI matched a server endpoint: Token."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7398590Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ProcessRequestContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+InferEndpointType."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7398860Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ProcessRequestContext was successfully processed by Volo.Abp.Account.Web.Pages.Account.OpenIddictImpersonateInferEndpointType."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7399110Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ProcessRequestContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+ValidateTransportSecurityRequirement."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7399300Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ProcessRequestContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+ValidateHostHeader."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7401030Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ExtractTokenRequestContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+ExtractPostRequest`1[[OpenIddict.Server.OpenIddictServerEvents+ExtractTokenRequestContext, OpenIddict.Server, Version=5.0.0.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7401280Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ExtractTokenRequestContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+ValidateClientAuthenticationMethod`1[[OpenIddict.Server.OpenIddictServerEvents+ExtractTokenRequestContext, OpenIddict.Server, Version=5.0.0.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7401480Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ExtractTokenRequestContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+ExtractBasicAuthenticationCredentials`1[[OpenIddict.Server.OpenIddictServerEvents+ExtractTokenRequestContext, OpenIddict.Server, Version=5.0.0.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7401840Z level=info msg="The token request was successfully extracted: {
[auth-server_ba5ce108-f]: 'grant_type': 'auto_token',
[auth-server_ba5ce108-f]: 'u': '',
[auth-server_ba5ce108-f]: 'redirect_uri': 'https://localhost:4200/',
[auth-server_ba5ce108-f]: 'client_id': 'Angular'
[auth-server_ba5ce108-f]: }."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7401910Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ProcessRequestContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Exchange+ExtractTokenRequest."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7402670Z level=info msg="The token request was rejected because the 'auto_token' grant type is not supported."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7402740Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ValidateTokenRequestContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Exchange+ValidateGrantType."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7402810Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ValidateTokenRequestContext was marked as rejected by OpenIddict.Server.OpenIddictServerHandlers+Exchange+ValidateGrantType."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7402960Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ProcessRequestContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Exchange+ValidateTokenRequest."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7403010Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ProcessRequestContext was marked as rejected by OpenIddict.Server.OpenIddictServerHandlers+Exchange+ValidateTokenRequest."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7403230Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ProcessErrorContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+AttachErrorParameters."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7403390Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ProcessErrorContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+AttachCustomErrorParameters."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7403790Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ApplyTokenResponseContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Exchange+NormalizeErrorResponse."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7404070Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ApplyTokenResponseContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+AttachHttpResponseCode`1[[OpenIddict.Server.OpenIddictServerEvents+ApplyTokenResponseContext, OpenIddict.Server, Version=5.0.0.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7404270Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ApplyTokenResponseContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+AttachCacheControlHeader`1[[OpenIddict.Server.OpenIddictServerEvents+ApplyTokenResponseContext, OpenIddict.Server, Version=5.0.0.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7404450Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ApplyTokenResponseContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+AttachWwwAuthenticateHeader`1[[OpenIddict.Server.OpenIddictServerEvents+ApplyTokenResponseContext, OpenIddict.Server, Version=5.0.0.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7404590Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ApplyTokenResponseContext was successfully processed by Volo.Abp.Account.Web.ExtensionGrants.LinkLoginExtensionGrantProcessJsonResponse."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7404810Z level=info msg="The response was successfully returned as a JSON document: {
[auth-server_ba5ce108-f]: 'error': 'unsupported_grant_type',
[auth-server_ba5ce108-f]: 'error_description': 'The specified 'grant_type' is not supported.',
[auth-server_ba5ce108-f]: 'error_uri': 'https://documentation.openiddict.com/errors/ID2032'
[auth-server_ba5ce108-f]: }."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7406190Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ApplyTokenResponseContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+ProcessJsonResponse`1[[OpenIddict.Server.OpenIddictServerEvents+ApplyTokenResponseContext, OpenIddict.Server, Version=5.0.0.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7406280Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ApplyTokenResponseContext was marked as handled by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+ProcessJsonResponse`1[[OpenIddict.Server.OpenIddictServerEvents+ApplyTokenResponseContext, OpenIddict.Server, Version=5.0.0.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7406370Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ProcessErrorContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Exchange+ApplyTokenResponse`1[[OpenIddict.Server.OpenIddictServerEvents+ProcessErrorContext, OpenIddict.Server, Version=5.0.0.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7406440Z level=debug msg="The event OpenIddict.Server.OpenIddictServerEvents+ProcessErrorContext was marked as handled by OpenIddict.Server.OpenIddictServerHandlers+Exchange+ApplyTokenResponse`1[[OpenIddict.Server.OpenIddictServerEvents+ProcessErrorContext, OpenIddict.Server, Version=5.0.0.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]."
[auth-server_ba5ce108-f]: ts=2024-08-12T04:55:51.7407760Z level=info msg="Request finished HTTP/1.1 POST https://localhost:44322/connect/token - 400 179 application/json;charset=UTF-8 3.2637ms"