Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Implementation of magic link login feature with...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
thori
October 08, 2019
Programming
620
1
Share
Implementation of magic link login feature with sorcery gem
thori
October 08, 2019
Other Decks in Programming
See All in Programming
Coding at the Speed of Thought: The New Era of Symfony Docker
dunglas
0
4.2k
生成 AI 時代のスナップショットテストってやつを見せてあげますよ(α版)
ojun9
0
330
Xdebug と IDE による デバッグ実行の仕組みを見る / Exploring-How-Debugging-Works-with-Xdebug-and-an-IDE
shin1x1
0
310
おれのAgentic Coding 2026/03
tsukasagr
1
120
20260315 AWSなんもわからん🥲
chiilog
2
180
ロボットのための工場に灯りは要らない
watany
12
3.3k
GoのDB アクセスにおける 「型安全」と「柔軟性」の両立 - Bob という選択肢
tak848
0
300
AI-DLC 入門 〜AIコーディングの本質は「コード」ではなく「構造」〜 / Introduction to AI-DLC: The Essence of AI Coding Is Not “Code” but “Structure”
seike460
PRO
0
170
脱 雰囲気実装!AgentCoreを良い感じにWEBアプリケーションに組み込むために
takuyay0ne
3
430
AWS×クラウドネイティブソフトウェア設計 / AWS x Cloud-Native Software Design
nrslib
16
3.5k
AI時代のシステム設計:ドメインモデルで変更しやすさを守る設計戦略
masuda220
PRO
6
1.2k
20260313 - Grafana & Friends Taipei #1 - Kubernetes v1.36 的開發雜記:那些困在 Alpha 加護病房太久的 Metrics
tico88612
0
250
Featured
See All Featured
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
500
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
370
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
170
Skip the Path - Find Your Career Trail
mkilby
1
93
So, you think you're a good person
axbom
PRO
2
2k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
250
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
190
For a Future-Friendly Web
brad_frost
183
10k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
The Spectacular Lies of Maps
axbom
PRO
1
670
Transcript
パスワードいらず、 sorceryでマジックリンクメールログイン 2019/10/9 堀 巧
Profile 堀 巧 / Takumi Hori テックリード@株式会社ライボ Ruby on Rails、Scala、Angular、 CakePHP、Docker、Vue.js
GitHub: @thori0908 Twitter: @hori_engineer 2
JobQ キャリアや転職に特化した匿名相談サービス • キャリアに関する相談 例、エンジニアになるか迷ってま す。。 • 企業の口コミ 例、あの会社の年収は? 社風は?
https://job-q.me 3
さらなる成長のためCakePHP2系からRailsへ移行中 色々あります手伝ってください... • CakePHP2系からRuby on Railsへ • jQuery廃止してVue.jsへ • インフラもEC2からECSへ
(dockerコンテナ化) • 仕様も変更 ◦ 使っていない機能削除 ◦ 使いやすいadmin画面に改善 4
エンジニア募集中! 5
admin画面のパスワード認証を楽にしたい パスワードあり • 簡単なパスワードにしてしまう 例、password, abcd1234 • パスワード管理ツール使う パスワードなし •
覚えなくて良い • セキュリティに強い • 探さなくて良い 6
マジックリンクメールで、 できます! 7
マジックリンクメールと は? 8
マジックリンクメールの仕組み • ユーザー登録後、フォームにemailを入力して送信する • マジックリンク付きメールが送られる • マジックリンクをクリックするとログインできる 9
どう実装するか 10
ユーザーとサーバーのやりとり マジックリンクメール click GET /login POST /login GET /auth/:token ログインフォーム
ログイントップ submit 送信完了画面 ユーザー側 サーバー側 11
必要なカラムをmigration • users.magic_login_token ◦ マジックリンクのtoken • users.magic_login_token_expires_at ◦ tokenの期限 •
users.magic_login_email_sent_at ◦ ログインメールの送信時刻 12
実装 GET /login 13
実装 POST /login • emailでDBからuserを取得 • token発行、tokenの期限設定 • ログインメールを送ってから、十分時間が立っているか ◦
hammering protectionという。(らしい • マジックリンクメールを送信 14
実装 GET /auth/:token • tokenでDBからuserを取得 • userのmagic_login_tokenとmagic_login_token_expires_at をNULLにする ◦ tokenは一度だけ使用できる
◦ セキュリティのため • ログイントップへリダイレクト 実装おしまい。 15
sorceryのsubmodule が便利です! (Readmeはないようですが作者の記事があります。 https://qiita.com/tonishi/items/832dbd6c1a0a012519fd 16
sorceryのsubmodule MagicLoginを使う • configファイル ◦ マジックログインに使うメールを指定 ◦ tokenの有効時間設定 • 必要なカラムを追加するmigrationファイル用意
◦ magic_login_token ◦ magic_login_token_expires_at ◦ magic_login_email_sent_at 17
sorceryの便利メソッド • deliver_magic_login_instructions! ◦ hammering protection ◦ ログインtoken発行、token期限指定 ◦ マジックリンクメール送信
• load_from_magic_login_token ◦ tokenでuserモデルを取得 ◦ tokenの期限をチェック • generate_magic_login_token ◦ token発行 18
運用時の懸念 19
運用時の問題 開発時運用 • 開発環境でメールを送信して、受け 取るのが面倒 ->ログにメールの内容を吐き出す 本番時運用 • メールが送られなくなったら、ユー ザーはログインできない
->スパム認定されないよう用心 20
まとめ • マジックリンクログインでパスワード管理から解放される • マジックリンク付きのメールを送るだけ • sorceryを使うと便利 21
おまけ passwordlessというgemでも実装できるらしい。 https://github.com/mikker/passwordless passwordlessはdeviseと併用できないらしい https://github.com/mikker/passwordless/issues/9 22