我想將OAuth添加到我正在使用Spring框架開發的其他服務中。我使用基於註釋的配置和spring-boot來運行它。oauth令牌端點的密碼
我有下面的類在我的項目:
@Configuration
@EnableWebSecurity
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecuritySettings extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("admin").password("123").authorities("ROLE_USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated()
.and().httpBasic().and().csrf().disable();
}
}
和我的授權服務器的配置如下:
@Configuration
@EnableAuthorizationServer
public static class MyAuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory().withClient("web")
.authorizedGrantTypes("password")
.authorities("ROLE_CLIENT","ROLE_TRUSTED_CLIENT","ROLE_USER")
.scopes("read", "write")
.resourceIds(RESOURCE_ID);
}
}
當我做一個GET請求來/oauth/token/
終點,我問輸入HTTP基本憑據。當我嘗試用admin
用戶登錄再下面是記錄
o.s.s.o.provider.endpoint.TokenEndpoint : Handling error: NoSuchClientException, No client with requested id: admin
輸入用戶名作爲web
的作品,但我不知道它的密碼。會記錄一個默認密碼,但它也不起作用。
Using default security password: f23087f8-58ce-e3d-bc62-58bf0963e75c
那麼這個密碼是什麼?我在哪裏可以找到它?我該如何設置它?
嗨!謝謝回覆。你是對的,那正是我想在這裏實現的。我只使用瀏覽器來嘗試用戶名/密碼組合。我實際上讀過你之前鏈接的頁面。文檔中的示例請求會發送'Authorization'標頭,所以在我的情況下它應該是'Basic encode64(web:webclientsecret)'。我對麼?我仍然無法實現它的工作。 – idursun
我終於得到它的工作。我接受你的答案,因爲它實際上回答了我的要求,所以我可以找出問題所在。 – idursun
我在研究與Spring OAuth2中的客戶機定義有關的另一個問題時找到了答案。你願意發表評論嗎?這裏是鏈接:http://stackoverflow.com/questions/36899386/null-client-in-oauth2-multi-factor-authentication – CodeMed