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
久々にコードを書いてOmniauthでハマった話
Search
Hiroaki Ninomiya
March 24, 2021
Programming
0
970
久々にコードを書いてOmniauthでハマった話
Fukuoka.rb 200回 LT大会 (#202)
https://fukuokarb.connpass.com/event/206956/
Hiroaki Ninomiya
March 24, 2021
Tweet
Share
More Decks by Hiroaki Ninomiya
See All by Hiroaki Ninomiya
渋谷アジャイルコミュニティへの想い #shibuyagile
treby
0
460
IM@Study活動紹介
treby
1
520
全ての雑用を、生まれる前に消し去りたい
treby
0
470
Webエンジニアからデータエンジニアへ転向している話 #pronama
treby
0
360
Rails 6.0の気になった新機能 #shuuumai
treby
1
690
Shinjuku.rbの移り変わりについて、あるいは大規模カンファレンスの知見を募集したい話 #tqrk13
treby
1
150
EMの悩みにフォーカスする #em_izakaya
treby
0
530
この先生きのこるためのエンジニアキャリア戦略パターン #em_meetup
treby
5
2.5k
失敗から学ぶEM方法論 #em_meetup
treby
0
1.4k
Other Decks in Programming
See All in Programming
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
770
42 best practices for Symfony, a decade later
tucksaun
1
180
バグを見つけた?それAppleに直してもらおう!
uetyo
0
180
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
260
Go の GC の不得意な部分を克服したい
taiyow
3
780
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
180
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
220
RWC 2024 DICOM & ISO/IEC 2022
m_seki
0
210
testcontainers のススメ
sgash708
1
120
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
130
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
33
1.5k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Gamification - CAS2011
davidbonilla
80
5.1k
Speed Design
sergeychernyshev
25
670
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Transcript
OmniauthͰϋϚͬͨ 2021/03/24 Fukuoka.rb 200ճLTେձ @treby006
About Me • treby (ͱΕͼʔ) • @treby006 • Shinjuku.rbͷੈ
About Me • ࣮(?)Ԭग़ • Ԭࢢ౦۠/۠ɺେໂాࢢʹ༝ԑ͕͋Γ·͢
About Me • ಠཱܥϕϯνϟʔΩϟϐλϧۈ • ελʔτΞοϓ͖͕ߴͯ͡ग़ࢿଆʹ • ҎલBtoCBtoBͷελʔτΞοϓͰRailsΤϯδχΞ • Rubyք۾ͩͱʮjoker͞Μ͕͍Δͱ͜ʯͰ௨͡Δ͔Βָ
• ITΛऔΓѻ͏͚ͲɺۀͰίʔυॻ͔ͳ͍
About Me • ಠཱܥϕϯνϟʔΩϟϐλϧۈ • ελʔτΞοϓ͖͕ߴͯ͡ग़ࢿଆʹ • ҎલBtoCBtoBͷελʔτΞοϓͰRailsΤϯδχΞ • Rubyք۾ͩͱʮjoker͞Μ͕͍Δͱ͜ʯͰ௨͡Δ͔Βָ
• ITΛऔΓѻ͏͚ͲɺۀͰίʔυॻ͔ͳ͍ => ͚Ͳॻ͖͍ͨ
ίʔυΛॻ͔ͳ͘ͳͬͯ͠·ͬͨਓ͋Δ͋ΔͷΈ • ࠷৽ͷٕज़ΛΩϟονΞοϓͰ͖ͳ͘ͳΔͷͰͳ͍͔ • ٕज़ྗ͕མͪͯ͠·͏ͷͰͳ͍͔ • ࣍ʹస৬ͨ͠ͱ͖ʹ։ൃऀͱͯ͠৯͍ͬͺ͙ΕΔͷͰͳ͍͔ • ͍͔ͭ͠ΩϟϦΞ͕த్ʹͳͬͯ͠·͏ͷͰͳ͍͔ •
ݱײ͕ͳ͘ͳͬͯ͠·͏ͷͰͳ͍͔
ίʔυΛॻ͔ͳ͘ͳͬͯ͠·ͬͨਓ͋Δ͋ΔͷΈ • ࠷৽ͷٕज़ΛΩϟονΞοϓͰ͖ͳ͘ͳΔͷͰͳ͍͔ • ٕज़ྗ͕མͪͯ͠·͏ͷͰͳ͍͔ • ࣍ʹస৬ͨ͠ͱ͖ʹ։ൃऀͱͯ͠৯͍ͬͺ͙ΕΔͷͰͳ͍͔ • ͍͔ͭ͠ΩϟϦΞ͕த్ʹͳͬͯ͠·͏ͷͰͳ͍͔ •
ݱײ͕ͳ͘ͳͬͯ͠·͏ͷͰͳ͍͔
ݱײ͕ͳ͘ͳΔͱԿ͕ྑ͘ͳ͍ͷ͔ • ۀ্ͷೳྗ͕Լ: ࢿݕ౼ͷࡍͷ։ൃྗݟཱͯ(σϡʔσϦδΣϯε) • ར͖͕Ͱ͖ͳ͘ͳ͍ͬͯ͘ͷͰʁ • ઐՈͱͯ͠ίϝϯτ͢Δ༰্͕Γͯ͠͠·͏ͷͰʁ • ͋Δࣄྫʹ৮Εͨ࣌ʹʮࣗͷݴ༿ʯͰͤͳ͍Ͳ͔͠͞
• ͰɺͲ͏͢Δʁ
ͦ͏ͩɺ։ൃ͠Α͏
αΠυϓϩδΣΫτɺ͡Ί·ͨ͠ • ਓͱझຯϓϩμΫτ࡞Γ / ։ൃΛঠ͢ΔཱͪҐஔ • LINEͷϛχΞϓϦ(ࠓεςϧε) / ۙʑ͓൸࿐Ͱ͖Δͱྑ͍ͳ •
جຊతʹθϩ͔Βͷ্ཱͪ͛(1݄ʙ) • ։ൃج൫࡞ΓνʔϜϏϧσΟϯάͰָ͖͍ͯ͠
γεςϜߏਤ
ٕज़ελοΫ • ϑϩϯτ(LIFFΞϓϦ): Vue CLI (webpackerෆ༻) • Next.js on Vercel
• αʔό: Rails 6.1.3 (Ruby 3.0) on Heroku • omniauth • administrate • ridgepole • crono_trigger
ٕज़ελοΫ • ϑϩϯτ(LIFFΞϓϦ): Vue CLI (webpackerෆ༻) • Next.js on Vercel
• αʔό: Rails 6.1.3 (Ruby 3.0) on Heroku • omniauth • administrate • ridgepole • crono_trigger
omniauth • ϚϧνϓϩόΠμͷೝূΛఏڙ͢Δgem • ʮSNSϩάΠϯʯΛ࣮͢Δͷʹྑ͘ΘΕΔΠϝʔδ • ࣮ʹར༻͍ͨ͠ϓϩόΠμ͚ͷϓϥάΠϯ͕ඞཁ • omniauth-twitteromniauth-githubͳͲ •
ཧը໘ͷ؆қϩάΠϯػೳͷͨΊʹ࠾༻ • LINEͷϛχΞϓϦͳͷͰLINEͱੑ͕ߴ͍ • omniauth-line ͱҰॹʹಋೖͯ͠LINEϩάΠϯ࣮ͩʂ
ಋೖ؆୯ • omniauth gemͱ͍͍ͨϓϩόΠμͷgemΛbundleͯ͠ Gemfile gem 'omniauth' gem 'omniauth-line'
ίʔϧόοΫΛड͚͚ΔΑ͏ʹͯ͠ • SessionsController ͱϧʔςΟϯάͷ४උ config/routes.rb get '/auth/:provider/callback', to: 'sessions#callback' post
'/auth/:provider/callback', to: 'sessions#callback' get '/logout', to: 'sessions#destroy', as: :logout
ϩάΠϯඞཁͳActionʹϦμΠϨΫτΛઃఆ AdminController before_action :authenticate_admin def authenticate_admin if current_admin_challenger.nil? redirect_to '/admin/auth/line'
end end
Callback URLͷϗϫΠτϦετొ(LINE)
Α࣮͠ߦͩ
͏·͍͔͘ͳ͍orz
ఆ֎ͷΤϥʔͩͬͨͷͰ • ϧʔςΟϯά͕ؒҧ͍ͬͯΔͷͰͳ͍͔ • typoͳ͍͔ • omniauth-line ͕ϝϯς͞Ε͍ͯͳ͍ͷͰ • omniauth
ͷgem·ͰΈʹ͍ͬͨ
ḷΓண͍ͨͷ • omniauthͷ༷มߋ • 2019ࠒͷมߋͰͨ͠ɻࣗͷແ͞Α…… • എܠ: ੬ऑੑCVE-2015-9284 ରԠΒ͍͠ •
CSRF͞ΕΔϦεΫ͕͋ΔΑ • GETͰ͍͚Δ͔Βҙਤ͠ͳ͍ϩάΠϯͤ͞ΒΕΔΑͶ(ͱ͍͏ཧղ) • ੬ऑੑ͔ͩΒରԠͨ͠ํ͕ྑ͍ • ͪΐͬͱͤྑ͍ͷͰͳ͘ɺຯʹରԠ͕໘
ྑ͘ͳ͍͚ͲɺΦϓγϣϯΛແޮԽͯ͠ରԠ • ੬ऑੑΔΘ͚Ͱ͕͢ɺҰ୴ྑ͍͔ͳɺͱ͍͏அ • ͜ΕͰಈ͖·ͨ͠ config/initializers/omniauth.rb Rails.application.config.middleware.use OmniAuth::Builder do configure
do |config| config.allowed_request_methods = %i[get post] config.silence_get_warning = true end : end
ͪΌΜͱରԠ͢ΔͳΒ • gemͬΆ͍ͷଘࡏ͍ͯ͠Δ: ೖΕΕྑ͍ͱ͍͏Θ͚Ͱͳ͍? • https://github.com/cookpad/omniauth-railscsrfprotection • ҰճϩάΠϯϘλϯ͕͋Δϖʔδʹඈ͢ײ͡ • ϦμΠϨΫτͰPOSTͤ͞Δͷͬͯ͘͠ͳ͍ʁ
• ৄ͘͠ͳ͍ͷͰڭ͍͑ͯͩ͘͞><
·ͱΊ • αΠυϓϩδΣΫτ͍͍ͧ • ݱײɺഓ͍ͬͯͧ͘ʂ • gemͷߋ৽ʹશવ͍͍͚ͭͯͯͳͯ͘ϫϩλ • खΛಈ͔ͯٔ͠ΕΔ͜ͱେࣄ
એ • ϙουΩϟετΛ͍ͬͯΔͷͰྑ͔ͬͨΒௌ͍ͯͶ • ͯ͘͠Ε͍͍ͯͷΑ
Happy Hacking!!