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
960
久々にコードを書いて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
410
IM@Study活動紹介
treby
1
510
全ての雑用を、生まれる前に消し去りたい
treby
0
470
Webエンジニアからデータエンジニアへ転向している話 #pronama
treby
0
360
Rails 6.0の気になった新機能 #shuuumai
treby
1
680
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
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.1k
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
580
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
ヤプリ新卒SREの オンボーディング
masaki12
0
130
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
170
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
230
Outline View in SwiftUI
1024jp
1
330
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
100
Featured
See All Featured
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Done Done
chrislema
181
16k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Agile that works and the tools we love
rasmusluckow
327
21k
Bash Introduction
62gerente
608
210k
Building Your Own Lightsaber
phodgson
103
6.1k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
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!!