Module: RailsIam::AuthConcern
- Extended by:
- ActiveSupport::Concern
- Included in:
- AuthController, RailsIam::Authorization::Authorizable
- Defined in:
- app/controllers/concerns/rails_iam/auth_concern.rb
Instance Method Summary collapse
- #current_refresh_token ⇒ Object
- #extract_refresh_token ⇒ Object
- #extract_refresh_token_from_cookie ⇒ Object
- #extract_refresh_token_from_header ⇒ Object
- #render_rails_iam_authentication_error(exception) ⇒ Object
- #render_rails_iam_authorization_error(exception) ⇒ Object
Instance Method Details
#current_refresh_token ⇒ Object
17 18 19 20 21 22 |
# File 'app/controllers/concerns/rails_iam/auth_concern.rb', line 17 def current_refresh_token return unless (refresh_token = extract_refresh_token) digest = Digest::SHA256.hexdigest(refresh_token) RailsIam::RefreshToken.find_by(token_digest: digest) end |
#extract_refresh_token ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/concerns/rails_iam/auth_concern.rb', line 24 def extract_refresh_token if authentication_strategies.include?(:cookie) token = return token if token.present? end case refresh_token_transport when :header extract_refresh_token_from_header when :request_body params[:refresh_token] else raise RailsIam::Authentication::Exceptions::AuthenticationError, refresh_token_transport_error end end |
#extract_refresh_token_from_cookie ⇒ Object
13 14 15 |
# File 'app/controllers/concerns/rails_iam/auth_concern.rb', line 13 def request..encrypted[refresh_token_key] end |
#extract_refresh_token_from_header ⇒ Object
7 8 9 10 11 |
# File 'app/controllers/concerns/rails_iam/auth_concern.rb', line 7 def extract_refresh_token_from_header header_key = "HTTP_#{refresh_token_key.upcase}" request.get_header(header_key) end |
#render_rails_iam_authentication_error(exception) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'app/controllers/concerns/rails_iam/auth_concern.rb', line 51 def render_rails_iam_authentication_error(exception) render json: { message: exception., code: "unauthorized".upcase, status: 401, url: request.original_fullpath, }, status: :unauthorized end |
#render_rails_iam_authorization_error(exception) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'app/controllers/concerns/rails_iam/auth_concern.rb', line 42 def (exception) render json: { message: exception., code: "forbidden".upcase, status: 403, url: request.original_fullpath, }, status: :forbidden end |