AngularJS で認証の仕組みをどう扱うのか? これが悩ましい問題。 サンプルのAngularJS の認証の仕組みを見ると、Cookie を使ってサーバとやりとりをしているが、これだと前回紹介した理想的な Rails, AngularJS 環境の構築 - ボクココ のようなAPIとしてのきり分けができず、結局Cookieを使ったWeb用のソースがサーバ側で必要になってしまう。これではスマホアプリを作るときに同じAPIのコードを使えない。 てことで認証はOAuthのみで扱うようにする。Rails にはOAuth用の素晴らしいライブラリ、「Doorkeeper」というのがOSSであるので、これを使う。 Doorkeeperがアクセストークンの発行、アクセストークンのチェック、外部アプリ連携など、一通りのAPIによるOAuth認証の枠組みを提供してくれる。そしてソースは割とよみやすい。 今回