Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 5 years have passed since last update.

APIでログインする時、以降のAPIコールにログインしたっていう認証かけたい時の話

Last updated at Posted at 2019-09-03

★殴り書き

ログインAPIとブラウザが同ドメイン
→クッキー使う

ログインAPIとブラウザが別ドメイン

ログインAPIとログイン後APIが同ドメイン
→クッキー使う

ログインAPIとログイン後APIが別ドメイン
→ドメイン別でも同じリソース(Redis)にアクセスできる場合
 ログインしたっていう情報をRedisに適当なハッシュをキーにして保存し、レスポンスとしてそれを返す。
 後は、APIコール時にハッシュキーを送ってもらって、そのハッシュキーに該当するキーがRedisに入っていればOK

SPAの場合は、ログインAPIのレスポンスのキーを保持して、別APIコールする時に付与すればいいだけな気もする。。

javasciptで画面遷移させる(window.location.hrefを変える)場合は、その時にキーをURLのパラメータにつけてしまえば何とかなる気もする。
※極論いうと、キーをセッションに格納させるためだけのURLを用意して、ログインAPI成功後そこに一回遷移させる(パラメータにログインAPIが返したキーを付けて遷移させる)、とかすればキーの受け渡しができる

→localStorageをクロスドメインさせる

どの状況でもOK
→OpenIDconnect
("authorization code flow" は重いので "implicit flow"
※自分たちしか使わない認証であれば、OpenIDconectもどきで良いと思う。。

ブラウザへの場合はリダイレクトのパラメータにIDトークンを付ける
APIの場合は普通にヘッダにIDトークン付ける

localStrageにIDトークンを保持する必要があるので、セキュアじゃないという突っ込みあり↓(この人はAuth0を推奨している)
https://tech.hicustomer.jp/posts/modern-authentication-in-hosting-spa/

0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?