Class: Intermodal::Rack::Auth
- Inherits:
-
Object
- Object
- Intermodal::Rack::Auth
- Defined in:
- lib/intermodal/rack/auth.rb
Constant Summary collapse
- UNAUTHORIZED =
[401, {}, []]
- IDENTITY =
'HTTP_X_AUTH_IDENTITY'
- KEY =
'HTTP_X_AUTH_KEY'
Class Method Summary collapse
Class Method Details
.call(env) ⇒ Object
USAGE:
(1) Define ::AccessCredential.authenticate!(identity, key) and returns an account object (2) Define ::AccessToken.generate!(account) and inserts token for authentication
You can inherit from Intermodal::Auth::AccessToken
(3) Add to routes:
match '/auth', :to => Intermodal::Rack::Auth
21 22 23 24 25 |
# File 'lib/intermodal/rack/auth.rb', line 21 def call(env) return UNAUTHORIZED unless valid?(env) && ( account = ::AccessCredential.authenticate!(env[IDENTITY], env[KEY])) access_token = ::AccessToken.generate!(account) [ 204, { 'X-Auth-Token' => access_token.to_s }, []] end |