OAuth2のSpringブートサポートと最低限必要な構成を学習するために、「Hello world」タイプの演習をコーディングしてみました。OAuth2サーバーとクライアントの最小スプリングブート構成
コンポーネント:
- I:ユーザーを認証する認証サーバーを呼び出します、と彼に
期待流れを迎えるだろう
- 認証サーバ
- Webアプリケーション、 webappを開く
- 私はredirを得る認証サーバー
- にected私は(Webアプリケーションは、認証サーバから自分のユーザー名を取得する必要があります)私が挨拶を参照してください私は戻ってWebアプリケーション
- にリダイレクトされます私は要求された範囲
- を承認する認証サーバー
- にログイン
401:アクセストークンを取得できませんでした。 最後のリダイレクトリンクはhttp://localhost:9001/ui/login?code=wcXMG4&state=JEEYqC
です。以下のコード&の設定は、私の予想されるフローで十分であると仮定することはあまりありませんか?
認証サーバー:
@SpringBootApplication
@EnableAuthorizationServer
@EnableResourceServer
@RestController
public class AuthServer {
public static void main(String[] args) {
SpringApplication.run(AuthServer.class);
}
@GetMapping("/whois")
Principal whois(Principal principal) {
return principal;
}
}
認証サーバープロパティ:
server.port=9000
server.contextPath=/sso
security.user.name=joe
security.user.password=password
security.oauth2.client.clientId=SOMEAPP
security.oauth2.client.clientSecret=SECRET
security.oauth2.client.authorized-grant-types=authorization_code,refresh_token,password
security.oauth2.client.scope=read
security.oauth2.resource.userInfoUri=http://localhost:9000/sso/whois
のWebapp:
@SpringBootApplication
@EnableOAuth2Sso
@RestController
public class UiServer {
public static void main(String[] args) {
SpringApplication.run(UiServer.class);
}
@GetMapping("/")
String helloWorld(Principal principal) {
return "Yay, auth server provided identity, you are " + principal;
}
}
のWebapp特性:
server.port=9001
server.contextPath=/ui
security.oauth2.client.client-id=SOMEAPP
security.oauth2.client.client-secret=SECRET
security.oauth2.client.accessTokenUri=http://localhost:9000/sso/oauth/access_token
security.oauth2.client.userAuthorizationUri=http://localhost:9000/sso/oauth/authorize
security.oauth2.resource.user-info-uri=http://localhost:9000/sso/whois