日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

springboot oauth 鉴权之——password、authorization_code鉴权

發布時間:2025/3/17 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 springboot oauth 鉴权之——password、authorization_code鉴权 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

參考一下兩個案例:https://www.cnblogs.com/haoliyou/p/9606018.html

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??https://www.cnblogs.com/haoliyou/p/9606036.html

.authorizedGrantTypes("authorization_code", "password", "refresh_token")//授權碼模式和password模式

package com.auth.server.config;import javax.sql.DataSource;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; import org.springframework.security.oauth2.provider.token.TokenStore; import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore;/*** 授權配置* @author wb0024**/ @Configuration @EnableAuthorizationServer public class ServerConfig extends AuthorizationServerConfigurerAdapter {@Autowiredprivate AuthenticationManager authenticationManager;@Qualifier("myUserDetailsService")@Autowiredprivate UserDetailsService userDetailsService;// @Autowired // @Qualifier("dataSource") // private DataSource dataSource;@Overridepublic void configure(AuthorizationServerSecurityConfigurer security) throws Exception {// 配置token獲取和驗證時的策略security.tokenKeyAccess("permitAll()").checkTokenAccess("isAuthenticated()");}@Overridepublic void configure(ClientDetailsServiceConfigurer clients) throws Exception {clients.inMemory().withClient("client")// secret密碼配置從 Spring Security 5.0開始必須以 {加密方式}+加密后的密碼 這種格式填寫/* * 當前版本5新增支持加密方式:* bcrypt - BCryptPasswordEncoder (Also used for encoding)* ldap - LdapShaPasswordEncoder* MD4 - Md4PasswordEncoder* MD5 - new MessageDigestPasswordEncoder("MD5")* noop - NoOpPasswordEncoder* pbkdf2 - Pbkdf2PasswordEncoder* scrypt - SCryptPasswordEncoder* SHA-1 - new MessageDigestPasswordEncoder("SHA-1")* SHA-256 - new MessageDigestPasswordEncoder("SHA-256")* sha256 - StandardPasswordEncoder*/.secret("{noop}secret").scopes("all").authorizedGrantTypes("authorization_code", "password", "refresh_token")//授權碼模式和password模式.autoApprove(true);}@Overridepublic void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { // // 配置tokenStore,保存到redis緩存中 // endpoints.authenticationManager(authenticationManager) // .tokenStore(new MyRedisTokenStore(redisConnectionFactory)) // // 不添加userDetailsService,刷新access_token時會報錯 // .userDetailsService(userDetailsService);// 使用最基本的InMemoryTokenStore生成tokenendpoints.authenticationManager(authenticationManager).tokenStore(memoryTokenStore());}// 使用最基本的InMemoryTokenStore生成token@Beanpublic TokenStore memoryTokenStore() {return new InMemoryTokenStore();} }

  

轉載于:https://www.cnblogs.com/haoliyou/p/9606055.html

總結

以上是生活随笔為你收集整理的springboot oauth 鉴权之——password、authorization_code鉴权的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。