Skip to content

Instantly share code, notes, and snippets.

@koji-k
Last active July 3, 2017 13:21
Show Gist options
  • Save koji-k/c1567b76e372714478c3319ed86a576e to your computer and use it in GitHub Desktop.
Save koji-k/c1567b76e372714478c3319ed86a576e to your computer and use it in GitHub Desktop.
GrailsのSpringSecurityRESTでの認証についてのメモ

GrailsのSpringSecurityREST(とSpringSecurityCore)を使って、RESTfulな認証を実現。

  1. クライアント(JavaScript)から、ユーザIDとパスワードをGrailsに送信
  2. 問題なければGrailsからaccess_tokenrefresh_tokenが返ってくる(とりあえずlocalStorageとかに保存)
  3. クライアントからGrailsのAPIを呼び出す際には、ヘッダーに「Authorization: Bearer サーバから貰ったaccess_token 」を指定して通信。
  4. access_tokenは制限時間有りなので、refresh_tokenを使って新しいaccess_tokenを再取得する。(できる)
     /oauth/access_tokenに対して、refresh_tokenを投げることで、2番と同様のフォーマットで新しいaccess_tokenが返ってくる。
     このパス(/oauth/access_token)は、URLMappingの設定で、permitAll(誰でもアクセス可)にしておく必要がある。 

    リファレンス: http://alvarosanchez.github.io/grails-spring-security-rest/latest/docs/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment