當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring Security OAuth2——自定义OAuth2第三方登录(Gitee)
生活随笔
收集整理的這篇文章主要介紹了
Spring Security OAuth2——自定义OAuth2第三方登录(Gitee)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
官方文檔
https://docs.spring.io/spring-security/site/docs/current/reference/html5/#oauth2login-custom-provider-properties
Gitee?OAuth2 文檔
https://gitee.com/api/v5/oauth_doc#/
解決方案
application.yml
spring:# Security Configsecurity:oauth2:client:registration:gitee:provider: giteeclient-id: {mm}client-secret: {mm}authorization-grant-type: authorization_coderedirect-uri: '{baseUrl}/login/oauth2/code/{registrationId}'scope: user_infoclient-name: Giteeclient-alias: giteeprovider:gitee:authorization-uri: https://gitee.com/oauth/authorizetoken-uri: https://gitee.com/oauth/tokenuser-name-attribute: iduser-info-uri: https://gitee.com/api/v5/user?WebSecurityConfigurerAdapter
@Overrideprotected void configure(HttpSecurity http)throws Exception{// OAuth2登錄http.oauth2Login().redirectionEndpoint().baseUri("/login/oauth2/code/*").and().userInfoEndpoint().customUserType(GiteeOAuth2User.class,"gitee").and().permitAll()}?GiteeOAuth2User
package com.hailiu.entity;import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.annotations.ApiModel; import lombok.Data; import lombok.EqualsAndHashCode; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.oauth2.core.user.OAuth2User;import java.io.Serializable; import java.util.Collection; import java.util.Date; import java.util.Map;/*** @author ShenTuZhiGang* @version 1.0.0* @date 2021-03-16 01:31*/ @Data @EqualsAndHashCode(callSuper = false) @ApiModel(value = "Gitee OAuth2用戶",description = "Gitee OAuth2用戶") public class GiteeOAuth2User implements OAuth2User, Serializable {private static final long serialVersionUID = 1L;private Integer id;private String login;private String name;@JsonProperty("avatar_url")private String avatarUrl;private String url;@JsonProperty("html_url")private String htmlUrl;@JsonProperty("followers_url")private String followersUrl;@JsonProperty("following_url")private String followingUrl;@JsonProperty("gists_url")private String gistsUrl;@JsonProperty("starred_url")private String starredUrl;@JsonProperty("subscriptions_url")private String subscriptionsUrl;@JsonProperty("organizations_url")private String organizationsUrl;@JsonProperty("repos_url")private String reposUrl;@JsonProperty("events_url")private String eventsUrl;@JsonProperty("received_events_url")private String receivedEventsUrl;private String type;private String blog;private String weibo;private String bio;@JsonProperty("public_repos")private Integer publicRepos;@JsonProperty("public_gists")private Integer publicGists;private Integer followers;private Integer following;private Integer stared;private Integer watched;@JsonProperty("created_at")private Date createdAt;@JsonProperty("updated_at")private Date updatedAt;private String email;@Overridepublic String getName() {return name;}@Overridepublic Map<String, Object> getAttributes() {return null;}@Overridepublic Collection<? extends GrantedAuthority> getAuthorities() {return null;} }參考文章
Web三方登錄實現(xiàn)(基于OAuth2.0,包含Github和QQ登錄,附源碼)
總結
以上是生活随笔為你收集整理的Spring Security OAuth2——自定义OAuth2第三方登录(Gitee)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring Boot——Spring
- 下一篇: Spring Security OAut