【问题标题】:Can i use both grant_type=password and grant_type=authorization_code in same project for oauth2 in spring boot我可以在 Spring Boot 的 oauth2 的同一个项目中同时使用 grant_type=password 和 grant_type=authorization_code
【发布时间】:2023-04-06 19:35:01
【问题描述】:

请告诉我,情况是如果我使用 Alexa,那么我们的项目应该实现 grant_type=authorization_code,而使用我们自己的移动应用时,我们需要 grant_type=password,这可能吗?

【问题讨论】:

    标签: java spring-boot oauth-2.0


    【解决方案1】:

    是的,你可以。 当您存储客户端时,您为它们分配允许的授权类型(例如密码、授权码)。

    例如,看下面的代码:

    clients.inMemory()
            .withClient("my-trusted-client")
                .authorizedGrantTypes("password", "authorization_code", "refresh_token", "implicit")
                .authorities("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT")
                .scopes("read", "write", "trust")
                .secret("secret")
                .accessTokenValiditySeconds(120).//Access token is only valid for 2 minutes.
                refreshTokenValiditySeconds(600);//Refresh token is only valid for 10 minutes.
    }
    

    my-trusted-client 客户端可以使用密码或授权码。

    sn-p 来自this guide,强烈建议您与this one 一起关注。此外,请注意,您应该阅读OAuth2 RFC。这是了解流程的最佳指南。

    【讨论】:

    • thna 很多,是的,我尝试将两者都包含在我的项目中,并且都可以独立工作,thnx
    • 如果这是您问题的解决方案,请考虑选择答案。谢谢。 stackoverflow.com/help/accepted-answer
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-31
    • 1970-01-01
    • 2018-09-25
    • 2020-05-26
    • 2011-04-13
    • 2012-05-23
    • 2018-10-08
    相关资源
    最近更新 更多