Class: Melaya::AuthAPI

Inherits:
Object
  • Object
show all
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

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).

Parameters:

  • current_password (String)
  • new_password (String)


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

#checkObject

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.

Parameters:

  • email (String)


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.

Parameters:

  • username (String)
  • password (String)


20
21
22
23
24
# File 'lib/melaya/auth.rb', line 20

def (username:, password:)
  @http.post("/api/v1/private/auth/login",
    "username" => username,
    "password" => password)
end

#meObject

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.

Parameters:

  • code (String)


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_setupObject

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_statusObject

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_handoffObject

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

#permissionsObject

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 permissions
  @http.get("/api/v1/private/auth/permissions")
end

#refreshObject

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.

Parameters:

  • email (String)


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.

Parameters:

  • token (String)
  • new_password (String)


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.

Parameters:

  • challenge_token (String)
  • code (String)

    TOTP or recovery code



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.

Parameters:

  • token (String)


48
49
50
# File 'lib/melaya/auth.rb', line 48

def (token:)
  @http.post("/api/v1/private/auth/verify-signup", "token" => token)
end