0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

FirebaseでSSOをやってみた(非推奨)

Last updated at Posted at 2021-08-09

非推奨としているのはローカルで実験したのみで、セキュリティリスクをあまり考慮していないからです。

最初に

今回のやり方はFirebase公式で紹介されている方法ではないです。
とりあえずローカル環境で動かしたってだけなのでセキュリティについても漏れがあります。
また、参考にした記事にあるcsstは実装していません。もし本番運用される際は理解した上で追加実装してください。

(参考記事で紹介されているcsstはCSRF対策のもので、CSRFトークンではなくJWTで対応したのだと思います)

構成図

firebase-sso-sample.jpg

実装

Vue

Vue.jsのメインとなるコードはこれだけです。

xxx.js
const response = await axios.get('http://localhost:5000/customToken', {withCredentials: true});
firebase.auth().signInWithCustomToken(response.data.firebaseToken);

Tips: ProjectBのAuthenticationにユーザーが存在しなくても、signInWithCustomTokenで認証できます。

Express

最後に

認証周りの実装は考慮することが多くて大変ですね。
ProjectAのAutheticationをAuth0に置き換えれば Sessionを使うことなくSSOの実現が可能です。

Auth0は公式でSSOの実装例、Firebaseとの連携方法も紹介されています。詳しい料金は調べてませんが、月1万、年12万で認証周りのセキュリティが強化でき、保守コストが下がるなら全然安いと感じました。

参考

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?