Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 带REST请求的Spring OAuth2身份验证_Java_Spring Security_Spring Oauth2 - Fatal编程技术网

Java 带REST请求的Spring OAuth2身份验证

Java 带REST请求的Spring OAuth2身份验证,java,spring-security,spring-oauth2,Java,Spring Security,Spring Oauth2,背景 为了使用spring-security-OAuth2配置OAuth2服务器,我遵循了以下步骤 到目前为止,它是这样工作的: 当用户尝试连接到服务器时,将显示一个普通的旧身份验证对话框 如果提供了正确的凭据,则会将用户重定向到默认的Spring确认表单 如果用户选择“允许”,则会使用可用于获取访问令牌的授权码将用户重定向到我想要的任何页面 SSCCE 我放置了这个准备运行的示例(这或多或少是教程给出的代码) 克隆到: git clone https://github.com/Arnaud

背景

为了使用spring-security-OAuth2配置OAuth2服务器,我遵循了以下步骤

到目前为止,它是这样工作的:

  • 当用户尝试连接到服务器时,将显示一个普通的旧身份验证对话框
  • 如果提供了正确的凭据,则会将用户重定向到默认的Spring确认表单
  • 如果用户选择“允许”,则会使用可用于获取访问令牌的授权码将用户重定向到我想要的任何页面
SSCCE

我放置了这个准备运行的示例(这或多或少是教程给出的代码)

克隆到:

git clone https://github.com/ArnaudDenoyelle/sscce-spring-oauth2.git
执行时:

mvn spring-boot:run
-user : user
-password : password
然后导航到:

http://localhost:9999/uaa/oauth/authorize?response_type=code&client_id=acme&redirect_uri=http://example.com
通过以下方式验证:

mvn spring-boot:run
-user : user
-password : password
问题

现在,我想改变行为:

  • 我更喜欢登录/密码表单,而不是普通的旧身份验证对话框
  • 我不想让第二步要求用户授权:我只想获得一个访问令牌
到目前为止,我可以通过以下步骤完成:

  • 用户以自定义形式输入其凭据
  • 我向
    http://localhost:9999/uaa/oauth/authorize?response_type=code&client_id=acme&redirect_uri=http://example.com
  • 我得到了一个HTML响应(这是确认表单),但如果它是HTTP 200,我并不真正关心它。它还为我提供了下一步所需的一些cookie
  • 我向
    http://localhost:9999/uaa/oauth/authorize
    与默认弹簧确认表发送的车身参数相同:
    • 用户\u oauth\u批准=真
    • scope.openid=true
它可以工作:用户被重定向到我想要的页面(在本例中:$authorization\u code$)

问题

我只想把Spring的确认表处理掉。在我的情况下,这是无用的:我只想获得当前会话的访问令牌,而不是永久授权客户端访问私有资源。有这样的配置吗

有关守则如下:

@SpringBootApplication
public class AuthserverApplication extends WebMvcConfigurerAdapter {

    public static void main(String[] args) {
        SpringApplication.run(AuthserverApplication.class, args);
    }

    @Configuration
    @EnableAuthorizationServer
    protected static class OAuth2Config extends AuthorizationServerConfigurerAdapter {

        @Autowired
        private AuthenticationManager authenticationManager;

        @Override
        public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
            endpoints.authenticationManager(authenticationManager);
        }

        @Override
        public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
            clients.inMemory()
                    .withClient("acme")
                    .secret("acmesecret")
                    .authorizedGrantTypes("authorization_code", "refresh_token", "password").scopes("openid");
        }

    }
}