15
Introduce to Warden @hieuk09

Introduce warden

Embed Size (px)

Citation preview

Page 1: Introduce warden

Introduce to Warden@hieuk09

Page 2: Introduce warden

about(me)

• @hieuk09

• Ruby Developer at TINYpulse

Page 3: Introduce warden

Why warden?

Page 4: Introduce warden

A peek at Devise

• 3178 commits

• 8311 LOC

• ~70 dependencies

• Only compatible with Rails

Page 5: Introduce warden

Warden

• A devise dependencies

• 287 commits

• 733 LOC

• ~ 20 dependencies

• Compatible with all Rack applications

Page 6: Introduce warden

What is warden?

• “Warden provides a mechanism for authentication in Rack based Ruby applications"

Page 7: Introduce warden

Some concepts

• Strategy

• Failure

• Callback

• User & Scope

• Session

Page 8: Introduce warden

Strategy

• How you authenticate

• Password

• OAuth

• Implement 2 methods: valid? & authenticate!

Page 9: Introduce warden

Failure

• A rack endpoint

• Handle failure for authentication

• In short: throw(:warden)

Page 10: Introduce warden

Callback

• Provide various callbacks to hook into in authentication cycle (set user, authenticate success, failure, …)

• Behave similar to Rails callbacks

Page 11: Introduce warden

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

Session

• Store user data in separate scope

• Access through session

• Work like a simple hash

Page 13: Introduce warden

Demo & Explain

Page 14: Introduce warden

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