Starts in:
2 DAYS
6 HRS
40 MIN
35 SEC
Starts in:
2 D
6 H
40 M
35 S
Open Closed

How to generate token from ABP Auth module for machine-to-machine #6245


User avatar
0
dev@veek.vn created

Hello!

I've recently set up a passwordless system in ABP where users enter their phone number, receive an OTP on their mobile, and then input this OTP on the website. Once the OTP is verified, I need to generate a token that will be sent back to the client. This token is then used for accessing the app and retrieving data.

Could you guide me on how to generate this token to send back to the client? Thanks a lot! Please note that this token is something similar to machine-to-machine token when there is no human interaction or confirmation

ABP Framework version: v.7.3.2

  • UI Type: Angular
  • Database System: MongoDB
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

19 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can consider to add a new grant type.

    https://community.abp.io/posts/how-to-add-a-custom-grant-type-in-openiddict.-6v0df94z

  • User Avatar
    0
    dev@veek.vn created

    Hi @maliming, it seems that I couldn't locate the AbpOpenIddictClaimDestinationsManager. Could you possibly assist with this?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    There are some changes that you might need to fix in your code. You can see the following list of the required changes:

    * `AbpOpenIddictClaimDestinationsManager` was renamed as `AbpOpenIddictClaimsPrincipalManager`. 
    * Use `AbpOpenIddictClaimsPrincipalManager.HandleAsync` instead of  `AbpOpenIddictClaimDestinationsManager.SetAsync`, which is removed.
    * `AbpDefaultOpenIddictClaimDestinationsProvider` was renamed as `AbpDefaultOpenIddictClaimsPrincipalHandler`.
    * `IAbpOpenIddictClaimDestinationsProvider` was renamed as `IAbpOpenIddictClaimsPrincipalHandler`.
    * Use `IAbpOpenIddictClaimsPrincipalHandler.HandleAsync` instead of  `IAbpOpenIddictClaimDestinationsProvider.SetAsync`, which is removed.
    * `AbpOpenIddictClaimDestinationsOptions` was renamed as `AbpOpenIddictClaimsPrincipalOptions`.
    

    Please check this PR if you encounter any problems related to OpenIddict Module.

  • User Avatar
    0
    dev@veek.vn created

    Hello,

    I've retrieved the client_id and client_secret from OpenIddictApplications, but I'm running into a snag: I keep getting an error that says "The specified client credentials are invalid." Do you have any idea what might be causing this?

    Additionally, I could use some guidance on how to generate the token and include it in the payload.

  • User Avatar
    0
    gterdem created
    Senior .NET Developer

    You should use Client Credentials Flow.

    We've a documentation that explains microservice-to-microservice communication: https://docs.abp.io/en/commercial/latest/startup-templates/microservice/synchronous-interservice-communication#client-credentials-flow

  • User Avatar
    0
    dev@veek.vn created

    I'm using a new grant type, and it's working wonderfully. Thank you so much for your help!

  • User Avatar
    0
    dev@veek.vn created

    Hi there! I noticed a problem when I included this setup. Interestingly, everything works fine if I remove it.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    This seems to be another problem. How do we reproduce this?

  • User Avatar
    0
    dev@veek.vn created

    In our authentication server project, I've added the setup and grant type configurations like above image. However, when I attempt to run the API through the endpoint 'domain/connect/token', I encounter an issue.

  • User Avatar
    0
    dev@veek.vn created

    hi @maliming, do you have any ideas?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Please share a simple template project to reproduce. Thanks.

    liming.ma@volosoft.com

  • User Avatar
    0
    dev@veek.vn created

    yes @maliming, pls check your mail

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Thanks. I will check it asap.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

     curl --location 'https://localhost:44369/connect/token' \
    --header 'Content-Type: application/x-www-form-urlencoded' \
    --data-urlencode 'grant_type=PasswordlessExtensionGrant' \
    --data-urlencode 'client_id=DemoNewGrantType_App' \
    --data-urlencode 'phoneNumber=0344446301' \
    --data-urlencode 'scope=openid offline_access DemoNewGrantType'
    {
      "access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6Ijg0NzZDOTUwQjYxOTY2MkY2QUU4MTlGOUVDNzdEMzI0QkMyNDFFRDQiLCJ4NXQiOiJoSGJKVUxZWlppOXE2Qm41N0hmVEpMd2tIdFEiLCJ0eXAiOiJhdCtq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WBOnY9yukzaEiqXsArgzlRUpqR2qq357c97RUenzLDWw6KFj7JfpCapKPK_dsPkw_FPbxUF0zeYXQEfDegoALEGI53YIfrjm8XPqIw1PlqNP4zegxpkpJ8cy0CBmyQzU4FPpenEG3GNGVqBhfvzjsI1IcsjtYb0CBjC0Uw2QFbF_qPPb8e7TLrg3qMQ9xYbmmoTaId6CEWKMfxVOgDzXacbkO5dS9H7eY_UaG0NjfIuz1-4Z3KdJZ6xljjNwnzfW3i7hbwRlAE664gtorbVCl0mTmZM6LSmsJhKjKzWfSusZQi62WMxOfh6QUkAYOMDMdxIbPwcu4KOvTcNvVOB8YpLkqHch-0RUCLiNeFOjsGG-RKhtg3hxIBN7RCaEI-Kv4hSUK-dd_4hUXQyOsPI3ftuJdTvRXVD7sINA-nh-DIafI_G0tLHryeIkVeC_1jPb6_ynlkb9IWDJ0G7AtYl6ivl85z4b4Z2YqQoZWv1FEidPXq_-S9E-dazmjiFMf-Mu7mCiJ7InOrZmrWlBsy4N-c2nQfkSsnmliUyKdx2ISyi0M8EdDJF5X7tHyLTO9Zu7VjayFGKXJHFB2dZxEUt6xrw665k7WdUeH9iiJBNRWXNpH6H6cC8SiHal4W4Hu97SSAuTJ6oyHviZkXkYjM8a33BGAIpGdKqauvBbutTcPA1x1mmOeasAsd9G_F92bmSZGs9gJrmK_YHrEXrU7vInM5MJtmC1GmTj0ayoen8XlKJ4LItZm6sV6UoJrILToU1t3vRJ-poCJ6F8GjAHq3ltGaydFjKkXlzGXRkxBWOSs5BXVIhJE6V287s0VD2jLhdLHsHPtusbtyfbe8RmqynnA4jBPxieM_xvRkhCYATrhgF-0vwJcrXFKXcYcig.K6TpJpgb98WJjt8_fgWQS98m42FD3pKaUvlQ1ZiIdMQ"
    }
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    You can also make it simple.

    public class PasswordlessExtensionGrant : ITokenExtensionGrant
    {
        public const string ExtensionGrantName = "PasswordlessExtensionGrant";
        public       string Name => ExtensionGrantName;
    
        public async Task<IActionResult> HandleAsync(ExtensionGrantContext context)
        {
            // get phone number from request
            var phoneNumber = context.Request.GetParameter("phoneNumber")?.Value?.ToString();
    
            if (string.IsNullOrEmpty(phoneNumber))
            {
                return new ForbidResult(new[] { OpenIddictServerAspNetCoreDefaults.AuthenticationScheme },
                                        properties: new AuthenticationProperties(new Dictionary<string, string>
                                        {
                                            [OpenIddictServerAspNetCoreConstants.Properties.Error] =
                                                OpenIddictConstants.Errors.InvalidGrant
                                        }!));
            }
    
            // retrieve user
            var userRepository = context.HttpContext.RequestServices.GetRequiredService<IRepository<IdentityUser, Guid>>();
            var user           = await userRepository.FirstOrDefaultAsync(x => x.PhoneNumber == phoneNumber);
    
            if (user == null)
            {
                return new ForbidResult(new[] { OpenIddictServerAspNetCoreDefaults.AuthenticationScheme },
                                        properties: new AuthenticationProperties(new Dictionary<string, string>
                                        {
                                            [OpenIddictServerAspNetCoreConstants.Properties.Error] = OpenIddictConstants.Errors.InvalidGrant
                                        }!));
            }
    
            var principal =  await context.HttpContext.RequestServices.GetRequiredService<IUserClaimsPrincipalFactory<IdentityUser>>().CreateAsync(user);
    
            // retrieve generic user claims
            var userClaimsPrincipalFactory = context.HttpContext.RequestServices.GetRequiredService<IUserClaimsPrincipalFactory<IdentityUser>>();
            var claimsPrincipal            = await userClaimsPrincipalFactory.CreateAsync(user);
    
            claimsPrincipal.SetScopes(principal.GetScopes());
            claimsPrincipal.SetResources(await GetResourcesAsync(context, principal.GetScopes()));
    
            // retrieve abp user claims
            var abpClaimsPrincipalFactory = context.HttpContext.RequestServices.GetRequiredService<IAbpClaimsPrincipalFactory>();
            var abpClaimsPrincipal        = await abpClaimsPrincipalFactory.CreateAsync(claimsPrincipal);
    
            await context.HttpContext.RequestServices.GetRequiredService<AbpOpenIddictClaimsPrincipalManager>().HandleAsync(context.Request, abpClaimsPrincipal);
    
            return new SignInResult(OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, abpClaimsPrincipal);
        }
    
    
        private async Task<IEnumerable<string>> GetResourcesAsync(ExtensionGrantContext context, ImmutableArray<string> scopes)
        {
            var resources = new List<string>();
            if (!scopes.Any())
            {
                return resources;
            }
    
            await foreach (var resource in context.HttpContext.RequestServices.GetRequiredService<IOpenIddictScopeManager>().ListResourcesAsync(scopes))
            {
                resources.Add(resource);
            }
    
            return resources;
        }
    }
    
  • User Avatar
    0
    dev@veek.vn created

    You can also make it simple.

    public class PasswordlessExtensionGrant : ITokenExtensionGrant 
    { 
        public const string ExtensionGrantName = "PasswordlessExtensionGrant"; 
        public       string Name => ExtensionGrantName; 
     
        public async Task<IActionResult> HandleAsync(ExtensionGrantContext context) 
        { 
            // get phone number from request 
            var phoneNumber = context.Request.GetParameter("phoneNumber")?.Value?.ToString(); 
     
            if (string.IsNullOrEmpty(phoneNumber)) 
            { 
                return new ForbidResult(new[] { OpenIddictServerAspNetCoreDefaults.AuthenticationScheme }, 
                                        properties: new AuthenticationProperties(new Dictionary<string, string> 
                                        { 
                                            [OpenIddictServerAspNetCoreConstants.Properties.Error] = 
                                                OpenIddictConstants.Errors.InvalidGrant 
                                        }!)); 
            } 
     
            // retrieve user 
            var userRepository = context.HttpContext.RequestServices.GetRequiredService<IRepository<IdentityUser, Guid>>(); 
            var user           = await userRepository.FirstOrDefaultAsync(x => x.PhoneNumber == phoneNumber); 
     
            if (user == null) 
            { 
                return new ForbidResult(new[] { OpenIddictServerAspNetCoreDefaults.AuthenticationScheme }, 
                                        properties: new AuthenticationProperties(new Dictionary<string, string> 
                                        { 
                                            [OpenIddictServerAspNetCoreConstants.Properties.Error] = OpenIddictConstants.Errors.InvalidGrant 
                                        }!)); 
            } 
     
            var principal =  await context.HttpContext.RequestServices.GetRequiredService<IUserClaimsPrincipalFactory<IdentityUser>>().CreateAsync(user); 
     
            // retrieve generic user claims 
            var userClaimsPrincipalFactory = context.HttpContext.RequestServices.GetRequiredService<IUserClaimsPrincipalFactory<IdentityUser>>(); 
            var claimsPrincipal            = await userClaimsPrincipalFactory.CreateAsync(user); 
     
            claimsPrincipal.SetScopes(principal.GetScopes()); 
            claimsPrincipal.SetResources(await GetResourcesAsync(context, principal.GetScopes())); 
     
            // retrieve abp user claims 
            var abpClaimsPrincipalFactory = context.HttpContext.RequestServices.GetRequiredService<IAbpClaimsPrincipalFactory>(); 
            var abpClaimsPrincipal        = await abpClaimsPrincipalFactory.CreateAsync(claimsPrincipal); 
     
            await context.HttpContext.RequestServices.GetRequiredService<AbpOpenIddictClaimsPrincipalManager>().HandleAsync(context.Request, abpClaimsPrincipal); 
     
            return new SignInResult(OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, abpClaimsPrincipal); 
        } 
     
     
        private async Task<IEnumerable<string>> GetResourcesAsync(ExtensionGrantContext context, ImmutableArray<string> scopes) 
        { 
            var resources = new List<string>(); 
            if (!scopes.Any()) 
            { 
                return resources; 
            } 
     
            await foreach (var resource in context.HttpContext.RequestServices.GetRequiredService<IOpenIddictScopeManager>().ListResourcesAsync(scopes)) 
            { 
                resources.Add(resource); 
            } 
     
            return resources; 
        } 
    } 
    

    I noticed the scope of this token is a bit limited. Could we look into adding more scope to it? This way, we can ensure it meets all our needs more effectively. Thanks for considering this!

  • User Avatar
    0
    dev@veek.vn created

    hi

     curl --location 'https://localhost:44369/connect/token' \ 
    --header 'Content-Type: application/x-www-form-urlencoded' \ 
    --data-urlencode 'grant_type=PasswordlessExtensionGrant' \ 
    --data-urlencode 'client_id=DemoNewGrantType_App' \ 
    --data-urlencode 'phoneNumber=0344446301' \ 
    --data-urlencode 'scope=openid offline_access DemoNewGrantType' 
    { 
      "access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6Ijg0NzZDOTUwQjYxOTY2MkY2QUU4MTlGOUVDNzdEMzI0QkMyNDFFRDQiLCJ4NXQiOiJoSGJKVUxZWlppOXE2Qm41N0hmVEpMd2tIdFEiLCJ0eXAiOiJhdCtqd3QifQ.eyJzdWIiOiI3NWZjNDI1Yy1mMDY3LTlmODQtZWNkMy0zYTBmNDZl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kw_FPbxUF0zeYXQEfDegoALEGI53YIfrjm8XPqIw1PlqNP4zegxpkpJ8cy0CBmyQzU4FPpenEG3GNGVqBhfvzjsI1IcsjtYb0CBjC0Uw2QFbF_qPPb8e7TLrg3qMQ9xYbmmoTaId6CEWKMfxVOgDzXacbkO5dS9H7eY_UaG0NjfIuz1-4Z3KdJZ6xljjNwnzfW3i7hbwRlAE664gtorbVCl0mTmZM6LSmsJhKjKzWfSusZQi62WMxOfh6QUkAYOMDMdxIbPwcu4KOvTcNvVOB8YpLkqHch-0RUCLiNeFOjsGG-RKhtg3hxIBN7RCaEI-Kv4hSUK-dd_4hUXQyOsPI3ftuJdTvRXVD7sINA-nh-DIafI_G0tLHryeIkVeC_1jPb6_ynlkb9IWDJ0G7AtYl6ivl85z4b4Z2YqQoZWv1FEidPXq_-S9E-dazmjiFMf-Mu7mCiJ7InOrZmrWlBsy4N-c2nQfkSsnmliUyKdx2ISyi0M8EdDJF5X7tHyLTO9Zu7VjayFGKXJHFB2dZxEUt6xrw665k7WdUeH9iiJBNRWXNpH6H6cC8SiHal4W4Hu97SSAuTJ6oyHviZkXkYjM8a33BGAIpGdKqauvBbutTcPA1x1mmOeasAsd9G_F92bmSZGs9gJrmK_YHrEXrU7vInM5MJtmC1GmTj0ayoen8XlKJ4LItZm6sV6UoJrILToU1t3vRJ-poCJ6F8GjAHq3ltGaydFjKkXlzGXRkxBWOSs5BXVIhJE6V287s0VD2jLhdLHsHPtusbtyfbe8RmqynnA4jBPxieM_xvRkhCYATrhgF-0vwJcrXFKXcYcig.K6TpJpgb98WJjt8_fgWQS98m42FD3pKaUvlQ1ZiIdMQ" 
    } 
    

    I've added more setup and it's not working.

    var issuerUrl = configuration["AuthServer:Authority"]; PreConfigure<OpenIddictServerBuilder>(builder => { builder.AddSigningCertificate(GetSigningCertificate(hostingEnvironment, configuration)); builder.AddEncryptionCertificate(GetSigningCertificate(hostingEnvironment, configuration));

    builder.SetIssuer(new Uri(issuerUrl)); builder.SetAuthorizationEndpointUris(new Uri(Url.Combine(issuerUrl, "connect/authorize"))); builder.SetTokenEndpointUris(new Uri(Url.Combine(issuerUrl, "connect/token"))); builder.SetIntrospectionEndpointUris(new Uri(Url.Combine(issuerUrl, "connect/introspect"))); builder.SetLogoutEndpointUris(new Uri(Url.Combine(issuerUrl, "connect/logout"))); builder.SetRevocationEndpointUris(new Uri(Url.Combine(issuerUrl, "connect/revocat"))); builder.SetUserinfoEndpointUris(new Uri(Url.Combine(issuerUrl, "connect/userinfo"))); builder.SetDeviceEndpointUris(new Uri(Url.Combine(issuerUrl, "connect/device"))); builder.SetCryptographyEndpointUris(new Uri(Url.Combine(issuerUrl, ".well-known/jwks"))); builder.SetIdentityTokenLifetime(TimeSpan.FromMinutes(60)); builder.SetAccessTokenLifetime(TimeSpan.FromMinutes(60)); builder.SetAuthorizationCodeLifetime(TimeSpan.FromMinutes(60)); builder.SetDeviceCodeLifetime(TimeSpan.FromMinutes(60)); builder.SetRefreshTokenLifetime(TimeSpan.FromMinutes(60)); builder.SetUserCodeLifetime(TimeSpan.FromMinutes(60)); builder.Configure(openIddictServerOptions => { openIddictServerOptions.GrantTypes.Add(PasswordlessExtensionGrant.ExtensionGrantName); }); });

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can add more scopes by claimsPrincipal.SetScopes("Your_Scope);

  • User Avatar
    0
    dev@veek.vn created

    thanks @maliming, it works now

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06