亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

來自數據庫的未經授權的錯誤 oauth2 客戶端

來自數據庫的未經授權的錯誤 oauth2 客戶端

墨色風雨 2022-06-30 10:18:20
我的應用程序中出現錯誤“未經授權”的問題。我正在使用 Spring Security 和 oauth2。我的客戶和用戶存儲在數據庫中。當我開始使用數據庫中的客戶端時,PostMan 中出現錯誤 401??蛻舳苏诒4嬖跀祿熘?,但是當我想從 localhost:8080/oauth/token 獲取令牌訪問權限時仍然出現錯誤。以下是我的來源:授權服務器配置:公共類 AuthorizationServerConfig 擴展 AuthorizationServerConfigurerAdapter {@Autowiredprivate AuthenticationManager authenticationManager;@Autowiredprivate TokenStore tokenStore;private CustomClientDetailsService customClientDetailsService;@BeanPasswordEncoder passwordEncoder() {    return PasswordEncoderFactories.createDelegatingPasswordEncoder();}@Overridepublic void configure(AuthorizationServerSecurityConfigurer security) throws Exception {    security.tokenKeyAccess("permitAll()")            .checkTokenAccess("isAuthenticated()");}@Overridepublic void configure(ClientDetailsServiceConfigurer clients) throws Exception {    clients.withClientDetails(customClientDetailsService);}@Overridepublic void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {    endpoints            .tokenStore(tokenStore)            .authenticationManager(authenticationManager);}}這是我的 CustomClientDetails :公共類 CustomClientDetails 實現 ClientDetails {final static Logger log = LoggerFactory.getLogger(CustomClientDetailsService.class);private static final long serialVersionUID = 6602529451366778198L;private Clients clients;public CustomClientDetails(final Clients clients){    this.clients = clients;}@Overridepublic String getClientId() {    return clients.getClientId();}@Overridepublic Set<String> getResourceIds() {    final Set<String> resourcesIds = new HashSet<String>();    resourcesIds.add(clients.getResourceIds());    return resourcesIds;}@Overridepublic boolean isSecretRequired() {    return true;}@Overridepublic String getClientSecret() {    return clients.getClientSecret();}@Overridepublic boolean isScoped() {    return true;}@Overridepublic Set<String> getScope() {    final Set<String> scopes = new HashSet<String>();    scopes.add(clients.getScope());    return scopes;}
查看完整描述

2 回答

?
慕后森

TA貢獻1802條經驗 獲得超5個贊

您應該在 postman 中提供 aclient_id和 a client_secret,在授權部分,您可以設置 Basic Auth。

http://img1.sycdn.imooc.com//62bd08240001d77e10740336.jpg

username字段中,輸入您的client_id和 在 中password,輸入您的client_secret.



查看完整回答
反對 回復 2022-06-30
?
搖曳的薔薇

TA貢獻1793條經驗 獲得超6個贊

“/oauth/token”中的“未經授權”可能意味著您沒有HTTP Basic Auth在請求標頭中提供憑據。據我所知,該端點默認情況下使用存儲在oauth_client_details實體中的登錄名和密碼進行保護。查找client_id+client_secret對并將其提供給 Postman 并使用 Authorization->Basic Auth 設置。



查看完整回答
反對 回復 2022-06-30
  • 2 回答
  • 0 關注
  • 158 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號