1
0
mirror of synced 2026-05-22 14:43:15 +00:00

access_token 读取兼容 Bearer Token 方式

This commit is contained in:
click33
2024-08-24 03:46:03 +08:00
parent a7a3e8c14f
commit 2d13e908b1
6 changed files with 46 additions and 21 deletions
@@ -4,8 +4,6 @@ import cn.dev33.satoken.oauth2.SaOAuth2Manager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.net.MalformedURLException;
/**
* 启动:Sa-OAuth2 Server端
* @author click33
@@ -13,7 +11,7 @@ import java.net.MalformedURLException;
@SpringBootApplication
public class SaOAuth2ServerApplication {
public static void main(String[] args) throws MalformedURLException {
public static void main(String[] args) {
SpringApplication.run(SaOAuth2ServerApplication.class, args);
System.out.println("\nSa-Token-OAuth2 Server端启动成功,配置如下:");
System.out.println(SaOAuth2Manager.getServerConfig());
@@ -1,6 +1,7 @@
package com.pj.oauth2;
import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.oauth2.SaOAuth2Manager;
import cn.dev33.satoken.oauth2.config.SaOAuth2ServerConfig;
import cn.dev33.satoken.oauth2.processor.SaOAuth2ServerProcessor;
import cn.dev33.satoken.oauth2.template.SaOAuth2Util;
@@ -8,7 +9,6 @@ import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
@@ -63,8 +63,9 @@ public class SaOAuth2ServerController {
// 获取 userinfo 信息:昵称、头像、性别等等
@RequestMapping("/oauth2/userinfo")
public SaResult userinfo(@RequestParam("access_token") String accessToken) {
public SaResult userinfo() {
// 获取 Access-Token 对应的账号id
String accessToken = SaOAuth2Manager.getDataResolver().readAccessToken(SaHolder.getRequest());
Object loginId = SaOAuth2Util.getLoginIdByAccessToken(accessToken);
System.out.println("-------- 此Access-Token对应的账号id: " + loginId);