module RailsApiAuth::Authentication
Module that defines attributes and method for use in controllers. This module would typically be included in the `ApplicationController`.
Public Instance Methods
authenticate!(*) { || ... }
click to toggle source
# File lib/rails_api_auth/authentication.rb, line 98 def authenticate!(*) @current_login = Login.where(oauth2_token: bearer_token).first! if block_given? head 401 unless yield else @current_login end rescue ActiveRecord::RecordNotFound head 401 end
bearer_token()
click to toggle source
# File lib/rails_api_auth/authentication.rb, line 117 def bearer_token auth_header = request.headers['Authorization'] auth_header ? auth_header.split(' ').last : nil end
consume_single_use_oauth2_token!()
click to toggle source
# File lib/rails_api_auth/authentication.rb, line 110 def consume_single_use_oauth2_token! @current_login = Login.where(single_use_oauth2_token: bearer_token).first! @current_login.refresh_single_use_oauth2_token! rescue ActiveRecord::RecordNotFound head 401 end