Sha256: 81965d01fd996d17c71faba6815797ce5956b64d74652cb2ed8ce23ba8d3f090
Contents?: true
Size: 783 Bytes
Versions: 2
Compression:
Stored size: 783 Bytes
Contents
module CruLib module AccessTokenProtectedConcern extend ActiveSupport::Concern protected def authenticate_request authenticate_token || render_unauthorized end def authenticate_token token = oauth_access_token_from_header return unless oauth_access_token_from_header @access_token = AccessToken.read(token) end # grabs access_token from header if one is present def oauth_access_token_from_header auth_header = request.env['HTTP_AUTHORIZATION'] || '' match = auth_header.match(/^Bearer\s(.*)/) return match[1] if match.present? false end def render_unauthorized headers['WWW-Authenticate'] = %{CAS realm="Application"} render_error('Bad token', status: 401) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
cru_lib-0.0.6 | lib/cru_lib/access_token_protected_concern.rb |
cru_lib-0.0.5 | lib/cru_lib/access_token_protected_concern.rb |