introduce warden
TRANSCRIPT
![Page 1: Introduce warden](https://reader031.vdocuments.site/reader031/viewer/2022021418/5a67b1e47f8b9a8b268b5ed1/html5/thumbnails/1.jpg)
Introduce to Warden@hieuk09
![Page 2: Introduce warden](https://reader031.vdocuments.site/reader031/viewer/2022021418/5a67b1e47f8b9a8b268b5ed1/html5/thumbnails/2.jpg)
about(me)
• @hieuk09
• Ruby Developer at TINYpulse
![Page 3: Introduce warden](https://reader031.vdocuments.site/reader031/viewer/2022021418/5a67b1e47f8b9a8b268b5ed1/html5/thumbnails/3.jpg)
Why warden?
![Page 4: Introduce warden](https://reader031.vdocuments.site/reader031/viewer/2022021418/5a67b1e47f8b9a8b268b5ed1/html5/thumbnails/4.jpg)
A peek at Devise
• 3178 commits
• 8311 LOC
• ~70 dependencies
• Only compatible with Rails
![Page 5: Introduce warden](https://reader031.vdocuments.site/reader031/viewer/2022021418/5a67b1e47f8b9a8b268b5ed1/html5/thumbnails/5.jpg)
Warden
• A devise dependencies
• 287 commits
• 733 LOC
• ~ 20 dependencies
• Compatible with all Rack applications
![Page 6: Introduce warden](https://reader031.vdocuments.site/reader031/viewer/2022021418/5a67b1e47f8b9a8b268b5ed1/html5/thumbnails/6.jpg)
What is warden?
• “Warden provides a mechanism for authentication in Rack based Ruby applications"
![Page 7: Introduce warden](https://reader031.vdocuments.site/reader031/viewer/2022021418/5a67b1e47f8b9a8b268b5ed1/html5/thumbnails/7.jpg)
Some concepts
• Strategy
• Failure
• Callback
• User & Scope
• Session
![Page 8: Introduce warden](https://reader031.vdocuments.site/reader031/viewer/2022021418/5a67b1e47f8b9a8b268b5ed1/html5/thumbnails/8.jpg)
Strategy
• How you authenticate
• Password
• OAuth
• Implement 2 methods: valid? & authenticate!
![Page 9: Introduce warden](https://reader031.vdocuments.site/reader031/viewer/2022021418/5a67b1e47f8b9a8b268b5ed1/html5/thumbnails/9.jpg)
Failure
• A rack endpoint
• Handle failure for authentication
• In short: throw(:warden)
![Page 10: Introduce warden](https://reader031.vdocuments.site/reader031/viewer/2022021418/5a67b1e47f8b9a8b268b5ed1/html5/thumbnails/10.jpg)
Callback
• Provide various callbacks to hook into in authentication cycle (set user, authenticate success, failure, …)
• Behave similar to Rails callbacks
![Page 11: Introduce warden](https://reader031.vdocuments.site/reader031/viewer/2022021418/5a67b1e47f8b9a8b268b5ed1/html5/thumbnails/11.jpg)
User & Scope
• Set & get user simply by set_user and user
• Scope of user for some scenarios:
• Multiple roles
• Stimulate another user
![Page 12: Introduce warden](https://reader031.vdocuments.site/reader031/viewer/2022021418/5a67b1e47f8b9a8b268b5ed1/html5/thumbnails/12.jpg)
Session
• Store user data in separate scope
• Access through session
• Work like a simple hash
![Page 13: Introduce warden](https://reader031.vdocuments.site/reader031/viewer/2022021418/5a67b1e47f8b9a8b268b5ed1/html5/thumbnails/13.jpg)
Demo & Explain
![Page 14: Introduce warden](https://reader031.vdocuments.site/reader031/viewer/2022021418/5a67b1e47f8b9a8b268b5ed1/html5/thumbnails/14.jpg)
Reference• https://github.com/hassox/warden/wiki
• https://rossta.net/blog/what-i-learned-about-hanami.html
• http://pothibo.com/2013/07/authentication-with-warden-devise-less/
• Demo code
• https://github.com/hieuk09/code_commenter
• https://github.com/hieuk09/code-commenter-hanami
![Page 15: Introduce warden](https://reader031.vdocuments.site/reader031/viewer/2022021418/5a67b1e47f8b9a8b268b5ed1/html5/thumbnails/15.jpg)