Class: RailsIam::AuthController
Instance Method Summary
collapse
#authentication_strategies, #authorization_rule_error, #cookie_options, #jwt_algorithm, #jwt_audience, #jwt_expiry, #jwt_issuer, #jwt_secret_key, #refresh_token_transport, #session_strategy, #user_class
#current_refresh_token, #extract_refresh_token, #extract_refresh_token_from_cookie, #extract_refresh_token_from_header, #render_rails_iam_authentication_error, #render_rails_iam_authorization_error
Instance Method Details
#refresh ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'app/controllers/rails_iam/auth_controller.rb', line 41
def refresh
refresh_token = current_refresh_token
validate_refresh_token(refresh_token)
user = refresh_token.user
jti = SecureRandom.uuid
new_access_token = RailsIam::Authentication::JwtEncoder.call(user, jti: jti)
cookies.encrypted[access_token_key] = {
value: new_access_token,
expires: access_token_expires_in,
**cookie_options,
}
refresh_token.update!(last_used_at: Time.current, jti: jti)
render json: { success: true }
end
|
#sign_in ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'app/controllers/rails_iam/auth_controller.rb', line 11
def sign_in
result = RailsIam::Authentication::Login.call(
email: login_params[:email],
password: login_params[:password],
request: request,
)
ensure_valid_strategy!
create_authenticated_user_cookies!(result) if strategy_includes?(:cookie)
if strategy_includes?(:bearer)
render json: token_response_payload(result)
else
render json: { user: result.user }
end
end
|
#sign_out ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
|
# File 'app/controllers/rails_iam/auth_controller.rb', line 29
def sign_out
refresh_token = current_refresh_token
RailsIam::Authentication::Logout.call(
refresh_token: refresh_token,
)
delete_authenticated_user_cookies! if strategy_includes?(:cookie)
head :no_content
end
|