Coder Social home page Coder Social logo

touch-and-learn-rails-authn's Introduction

Build and Learn Rails Authentication - Railsにおける認証技術の実装サンプル

Disclaimer

あくまで学習用サンプルであるため、可能な限りのセキュリティ面の配慮は行っていますが、本番環境のアプリケーションにそのまま使うことは控えてください。 万一コピペで使用したいという場合でも、適切なセキュリティレビューを経た上で使用するようにしてください。

実際の商用アプリケーションでこのコードを流用したことによって生じた損害の責任は負いかねます。

スライドのビルド

スライドはMarpを使ってMarkdownで作成しています。実際に発表に使ったスライドと同等のものを得るには、

cd slides
yarn
npx marp slides.md

とすればHTMLファイルを得ることができます。PDFファイルを得る場合は最後のコマンドを

npx marp slides.md --pdf --allow-local-files

とします。

SpeakerDeckにPDF版をアップロードしてあります。

動作にあたって

Rails consoleからユーザーを作成してください。

User.create(
  email: "[email protected]",
  password: "hogefuga",
  display_name: "Hoge"
)

メール送信は 作者のローカル環境がOP25Bされてるっぽいので LetterOpenerWebを使って擬似的にメール送信をする形にしています。LetterOpenerWebのインターフェースへのリンクはrootのURLに記載があります。

それぞれの機能に対応するコミットハッシュ

  • ログイン: c911d16075821eaa9f17a6c263560df875375adc
  • ログアウト: c23f67ba900ee5cabd7ad1e945135c459b898124
  • Cookieからの再ログイン(remember): 0986b228c02aa615af0a3b4cddccc0759b767f01
    • 5f2d088663e6ebbbc0530fc35b261f323ffb1f18: remember tokenが時間で無効化されていることが確認できたらユーザーからその値を消去する
  • ロックアウト: dd586a2019bda6d8bc9e5332af77b141a29717e9
    • exponential backoffで実装しているので、実際にその効果を確かめる場合は6〜10回くらいログインに連続で失敗させてデータベースの中身を見るとよいです
    • 5fbad9f8c84e79fdea0fb475d39c1f89e79fb098: ユーザーがロックアウトされているかのチェックを最優先する順序に変更した
  • Eメール認証: 388be28b6f13f6958f2e086819b33b3dc0ab03d6
    • d0ebf52d3ec01928ef8fe22d64ac6d5c85f88ea5: 期限のチェックが漏れていたのの追加
  • パスワードリセット: bd574b82a133247d95ab7fb730e2b0f831427058
  • Time-based OTP: 間に合わなかった…

touch-and-learn-rails-authn's People

Contributors

sylph01 avatar

Stargazers

zh8 avatar hoshino tsuyoshi avatar Seiei Miyagi avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.