小编for*_*ugh的帖子

spring security oauth2中的"无法获取访问令牌"错误

在我的spring项目中,我有一个在localhost:9999上运行的oauth2客户端应用程序和一个在localhost:8080上运行的oauth2授权服务器.结果,在批准页面之后,我看到错误页面,我不知道是什么问题?当按F12我看到set-cookie完成了!但/ oauth/token没有被调用!和/我也没有打电话!和浏览器不重定向到localhost:9999.

我的客户端应用

package sso.client;
import java.security.Principal;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@EnableAutoConfiguration
@Configuration
@EnableOAuth2Sso
@RestController
public class App {

  @RequestMapping("/")
  public String home(Principal user) {
    return "Hello " + user.getName();
  }

  public static void main(String[] args) {
    new SpringApplicationBuilder(App.class)
        .properties("spring.config.name=client").run(args);
  }

}
Run Code Online (Sandbox Code Playgroud)

client.yml

server:
  port: 9999
security:
  oauth2:
    client:
      client-id: acme
      client-secret: acmesecret
      access-token-uri: http://localhost:8080/oauth/token
      user-authorization-uri: http://localhost:8080/oauth/authorize
    resource:
      user-info-uri: http://localhost:8080/me
Run Code Online (Sandbox Code Playgroud)

我的授权服务器

package sso.raymon;

import java.security.Principal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import …
Run Code Online (Sandbox Code Playgroud)

spring oauth

5
推荐指数
0
解决办法
2719
查看次数

标签 统计

oauth ×1

spring ×1