微信、github登录开发(第三方登录)

1.第三方登录流程

(A)用户访问客户端,后者将前者导向认证服务器。

(B)用户选择是否给予客户端授权。

(C)假设用户给予授权,认证服务器将用户导向客户端事先指定的"重定向URI",同时附上一个授权 码。

(D)客户端收到授权码,附上早先的"重定向URI",向认证服务器申请令牌。这一步是在客户端的后 台的服务器上完成的,对用户不可见。

(E)认证服务器核对了授权码和重定向URI,确认无误后,向客户端发送访问令牌(access token)和 更新令牌(refresh token)。

2第三方登录简单实用

--登录微信开发平台注册

--封装一个常量类,主要是第三方登录需要的参数(需要去第三方网站注册)

public class WechatConstant {

//请求code的URL
public static final String CODE_URL = "https://open.weixin.qq.com/connect/qrconnect?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect";

//APPID
public static final String APPID = "xxxx";

//SECRET
public static final String SECRET = "xxxx";

//REDIRECT_URI
public static final String REDIRECT_URI = "xxxx";

--controller

@Controller
public class LoginController {

@RequestMapping(value = "/login",method = RequestMethod.GET)
public String login(Model model){
String url = WechatConstant.CODE_URL.replaceAll("APPID",WechatConstant.APPID)
.replaceAll("REDIRECT_URI",WechatConstant.REDIRECT_URI);//拼接地址

model.addAttribute("authenUrl",url);
return "forward:/login.jsp";
}



猜你喜欢

转载自www.cnblogs.com/wgyi140724-/p/10747514.html