Skip to main content

AuthAPI

client.AuthAPI covers account entry, session lifecycle, passkeys, email OTP, login-time 2FA verification, and personal API tokens.

Base path prefix: /main/api/v1/…

Snippets use ctx / client from Authentication unless noted.

Registration, login, email OTP, and 2FA verify

registerBody := analogwakatime.NewMainApiV1StartRegisterPostRequest(
"Ivan",
"correct-horse-battery-staple",
"TURNSTILE_TOKEN",
)
registered, _, err := client.AuthAPI.
MainApiV1StartRegisterPost(context.Background()).
MainApiV1StartRegisterPostRequest(*registerBody).
Execute()

loginBody := analogwakatime.NewMainApiV1StartLoginPostRequest(
"correct-horse-battery-staple",
"TURNSTILE_TOKEN",
)
login, _, err := client.AuthAPI.
MainApiV1StartLoginPost(context.Background()).
MainApiV1StartLoginPostRequest(*loginBody).
Execute()

otpBody := analogwakatime.NewVerifyEmailOtpRequest("CHALLENGE_TOKEN", "123456")
verified, _, err := client.AuthAPI.
VerifyEmailOtp(context.Background()).
VerifyEmailOtpRequest(*otpBody).
Execute()

resendBody := analogwakatime.NewResendEmailOtpRequest("CHALLENGE_TOKEN")
resent, _, err := client.AuthAPI.
ResendEmailOtp(context.Background()).
ResendEmailOtpRequest(*resendBody).
Execute()

twoFactorBody := analogwakatime.NewMainApiV1StartAuth2faVerifyPostRequest(
"CHALLENGE_TOKEN",
"123456",
)
authorized, _, err := client.AuthAPI.
MainApiV1StartAuth2faVerifyPost(context.Background()).
MainApiV1StartAuth2faVerifyPostRequest(*twoFactorBody).
Execute()

Login may return a challenge that must be completed with email OTP or 2FA.

Sessions

MethodHTTPDescription
GetCurrentSessionGET /get/my/sessionCurrent login session
ListLoginsGET /get/my/loginsActive sessions
RevokeLoginPOST /revoke/my/loginRevoke one session
RevokeOtherLoginsPOST /revoke/my/logins/othersRevoke other sessions
RevokeAllLoginsPOST /revoke/my/logins/allRevoke all sessions
RevokeCurrentLoginPOST /revoke/my/login/currentRevoke current session
currentSession, _, err := client.AuthAPI.GetCurrentSession(ctx).Execute()
allSessions, _, err := client.AuthAPI.ListLogins(ctx).Execute()

revokeBody := analogwakatime.NewRevokeLoginRequest("SESSION_ID")
revoked, _, err := client.AuthAPI.
RevokeLogin(ctx).
RevokeLoginRequest(*revokeBody).
Execute()

otherSessions, _, err := client.AuthAPI.RevokeOtherLogins(ctx).Execute()
allRevoked, _, err := client.AuthAPI.RevokeAllLogins(ctx).Execute()
currentRevoked, _, err := client.AuthAPI.RevokeCurrentLogin(ctx).Execute()

Passkeys

beginBody := analogwakatime.NewBeginPasskeyLoginRequest()

loginOptions, _, err := client.AuthAPI.
BeginPasskeyLogin(context.Background()).
BeginPasskeyLoginRequest(*beginBody).
Execute()

registrationOptions, _, err := client.AuthAPI.
BeginPasskeyRegistration(ctx).
BeginPasskeyLoginRequest(*beginBody).
Execute()

credential := map[string]interface{}{
"id": "CREDENTIAL_ID",
"rawId": "RAW_CREDENTIAL_ID",
"type": "public-key",
"response": map[string]interface{}{},
}

finishLogin := analogwakatime.NewFinishPasskeyLoginRequest("SESSION_ID", credential)
passkeyLogin, _, err := client.AuthAPI.
FinishPasskeyLogin(context.Background()).
FinishPasskeyLoginRequest(*finishLogin).
Execute()

finishRegistration := analogwakatime.NewFinishPasskeyRegistrationRequest("SESSION_ID", credential)
passkeyRegistration, _, err := client.AuthAPI.
FinishPasskeyRegistration(ctx).
FinishPasskeyRegistrationRequest(*finishRegistration).
Execute()

passkeys, _, err := client.AuthAPI.ListPasskeys(ctx).Execute()

renameBody := analogwakatime.NewRenamePasskeyRequest(1, "Work laptop")
renamed, _, err := client.AuthAPI.
RenamePasskey(ctx).
RenamePasskeyRequest(*renameBody).
Execute()

deleteBody := analogwakatime.NewDeletePasskeyRequest(1)
deleted, _, err := client.AuthAPI.
DeletePasskey(ctx).
DeletePasskeyRequest(*deleteBody).
Execute()

The WebAuthn credential map comes from the browser or platform authenticator.

API tokens

Create, list, update, and delete flows are documented in API tokens.