Commit c0c18634 by 朱瑞泽

暂定

parent 3624097a
......@@ -3,10 +3,15 @@ package com.gic.demo.single.web.controller;
import com.alibaba.fastjson.JSON;
import com.gic.authcenter.sdk.GicAuthcenterManager;
import com.gic.authcenter.sdk.exception.NoTokenCacheException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* GIC 认证中心 SDK 测试
*
......@@ -15,15 +20,29 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
public class AuthcenterTestController {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private GicAuthcenterManager gicAuthcenterManager;
/**
* @return 获取认证 url 用于前端访问
* @return 获取 oauth2 登录 url
*/
@RequestMapping("/get-oauth2-login-url")
public String getOAuth2LoginUrl() {
return gicAuthcenterManager.getAuthorizeUrl();
}
/**
* oauth2 登录
*/
@RequestMapping("/get-authcenter-url")
public String getAuthcenterUrl() {
return JSON.toJSONString(gicAuthcenterManager.getAuthorizeUrl());
@RequestMapping("/oauth2-login")
public void oauth2Login(HttpServletResponse response) {
try {
response.sendRedirect(gicAuthcenterManager.getAuthorizeUrl());
} catch (IOException e) {
logger.warn(e.getMessage());
}
}
/**
......
......@@ -14,10 +14,9 @@ public class GicAuthcenterTest {
GicAuthcenter gicAuthcenter = GicAuthcenter.build(GicAuthcenterConfig.build(
"gicplatformid",
"gicplatformsecret",
"http://127.0.0.1:9002/gic-demo-single-web/demo/get-access-token",
"https://www.gicdev.com/gic-authcenter"
));
System.out.println(gicAuthcenter.getAuthorizeUrl());
System.out.println(gicAuthcenter.getAuthorizeUrl("http://127.0.0.1:9002/gic-demo-single-web/demo/get-access-token"));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment