Class: Melaya::AuthAPI
- Inherits:
-
Object
- Object
- Melaya::AuthAPI
- Defined in:
- lib/melaya/auth.rb
Overview
Auth API — login, MFA, registration, password management, and session tokens.
Most endpoints are public (no Bearer token needed for login/register). However, the SDK HttpClient always sends the mk_* API key which is fine — the server simply ignores it for public routes.
Maps to /api/v1/private/auth/* and /api/v1/auth/*.
Instance Method Summary collapse
-
#change_password(current_password:, new_password:) ⇒ Object
POST /api/v1/private/auth/change-password Change password (current + new).
-
#check ⇒ Object
GET /api/v1/private/auth/check Lightweight session validity check; returns ok: true.
-
#forgot_password(email:) ⇒ Object
POST /api/v1/private/auth/forgot-password Initiate password reset flow; sends email with reset token.
-
#initialize(http) ⇒ AuthAPI
constructor
A new instance of AuthAPI.
-
#login(username:, password:) ⇒ Object
POST /api/v1/private/auth/login Password + username login; returns session JWT + optional MFA challenge token.
-
#me ⇒ Object
GET /api/v1/private/auth/me Return current authenticated user profile.
-
#mfa_confirm(code:) ⇒ Object
POST /api/v1/private/mfa/confirm Confirm TOTP setup with first valid code; activates MFA.
-
#mfa_setup ⇒ Object
POST /api/v1/private/mfa/setup Initiate TOTP setup; returns QR/secret.
-
#mfa_status ⇒ Object
GET /api/v1/private/mfa/status Return MFA enrollment status for the caller.
-
#mobile_handoff ⇒ Object
POST /api/v1/private/auth/mobile-handoff Create a short-lived handoff token for mobile app deep-link auth.
-
#permissions ⇒ Object
GET /api/v1/private/auth/permissions Return caller's permission flags (capabilities, tier, feature gates).
-
#refresh ⇒ Object
POST /api/v1/private/auth/refresh Rotate session JWT (sliding expiry); returns new token.
-
#register(username:, email:, password:) ⇒ Object
POST /api/v1/private/auth/register Create a new user account; sends email verification.
-
#resend_verification(email:) ⇒ Object
POST /api/v1/private/auth/resend-verification Re-send email verification message.
-
#reset_password(token:, new_password:) ⇒ Object
POST /api/v1/private/auth/reset-password Complete password reset using token from email.
-
#verify_mfa(challenge_token:, code:) ⇒ Object
POST /api/v1/private/auth/mfa/verify Resolve MFA challenge after login.
-
#verify_signup(token:) ⇒ Object
POST /api/v1/private/auth/verify-signup Confirm email address from signup link token.
Constructor Details
#initialize(http) ⇒ AuthAPI
Returns a new instance of AuthAPI.
12 13 14 |
# File 'lib/melaya/auth.rb', line 12 def initialize(http) @http = http end |
Instance Method Details
#change_password(current_password:, new_password:) ⇒ Object
POST /api/v1/private/auth/change-password Change password (current + new).
75 76 77 78 79 |
# File 'lib/melaya/auth.rb', line 75 def change_password(current_password:, new_password:) @http.post("/api/v1/private/auth/change-password", "currentPassword" => current_password, "newPassword" => new_password) end |
#check ⇒ Object
GET /api/v1/private/auth/check Lightweight session validity check; returns ok: true.
67 68 69 |
# File 'lib/melaya/auth.rb', line 67 def check @http.get("/api/v1/private/auth/check") end |
#forgot_password(email:) ⇒ Object
POST /api/v1/private/auth/forgot-password Initiate password reset flow; sends email with reset token.
84 85 86 |
# File 'lib/melaya/auth.rb', line 84 def forgot_password(email:) @http.post("/api/v1/private/auth/forgot-password", "email" => email) end |
#login(username:, password:) ⇒ Object
POST /api/v1/private/auth/login Password + username login; returns session JWT + optional MFA challenge token.
20 21 22 23 24 |
# File 'lib/melaya/auth.rb', line 20 def login(username:, password:) @http.post("/api/v1/private/auth/login", "username" => username, "password" => password) end |
#me ⇒ Object
GET /api/v1/private/auth/me Return current authenticated user profile.
61 62 63 |
# File 'lib/melaya/auth.rb', line 61 def me @http.get("/api/v1/private/auth/me") end |
#mfa_confirm(code:) ⇒ Object
POST /api/v1/private/mfa/confirm Confirm TOTP setup with first valid code; activates MFA.
133 134 135 |
# File 'lib/melaya/auth.rb', line 133 def mfa_confirm(code:) @http.post("/api/v1/private/mfa/confirm", "code" => code) end |
#mfa_setup ⇒ Object
POST /api/v1/private/mfa/setup Initiate TOTP setup; returns QR/secret.
126 127 128 |
# File 'lib/melaya/auth.rb', line 126 def mfa_setup @http.post("/api/v1/private/mfa/setup") end |
#mfa_status ⇒ Object
GET /api/v1/private/mfa/status Return MFA enrollment status for the caller.
120 121 122 |
# File 'lib/melaya/auth.rb', line 120 def mfa_status @http.get("/api/v1/private/mfa/status") end |
#mobile_handoff ⇒ Object
POST /api/v1/private/auth/mobile-handoff Create a short-lived handoff token for mobile app deep-link auth.
100 101 102 |
# File 'lib/melaya/auth.rb', line 100 def mobile_handoff @http.post("/api/v1/private/auth/mobile-handoff") end |
#permissions ⇒ Object
GET /api/v1/private/auth/permissions Return caller's permission flags (capabilities, tier, feature gates).
106 107 108 |
# File 'lib/melaya/auth.rb', line 106 def @http.get("/api/v1/private/auth/permissions") end |
#refresh ⇒ Object
POST /api/v1/private/auth/refresh Rotate session JWT (sliding expiry); returns new token.
112 113 114 |
# File 'lib/melaya/auth.rb', line 112 def refresh @http.post("/api/v1/private/auth/refresh") end |
#register(username:, email:, password:) ⇒ Object
POST /api/v1/private/auth/register Create a new user account; sends email verification.
38 39 40 41 42 43 |
# File 'lib/melaya/auth.rb', line 38 def register(username:, email:, password:) @http.post("/api/v1/private/auth/register", "username" => username, "email" => email, "password" => password) end |
#resend_verification(email:) ⇒ Object
POST /api/v1/private/auth/resend-verification Re-send email verification message.
55 56 57 |
# File 'lib/melaya/auth.rb', line 55 def resend_verification(email:) @http.post("/api/v1/private/auth/resend-verification", "email" => email) end |
#reset_password(token:, new_password:) ⇒ Object
POST /api/v1/private/auth/reset-password Complete password reset using token from email.
92 93 94 95 96 |
# File 'lib/melaya/auth.rb', line 92 def reset_password(token:, new_password:) @http.post("/api/v1/private/auth/reset-password", "token" => token, "newPassword" => new_password) end |
#verify_mfa(challenge_token:, code:) ⇒ Object
POST /api/v1/private/auth/mfa/verify Resolve MFA challenge after login.
30 31 32 33 34 |
# File 'lib/melaya/auth.rb', line 30 def verify_mfa(challenge_token:, code:) @http.post("/api/v1/private/auth/mfa/verify", "challengeToken" => challenge_token, "code" => code) end |
#verify_signup(token:) ⇒ Object
POST /api/v1/private/auth/verify-signup Confirm email address from signup link token.
48 49 50 |
# File 'lib/melaya/auth.rb', line 48 def verify_signup(token:) @http.post("/api/v1/private/auth/verify-signup", "token" => token) end |