Skip to main content

DeviceAuthAPI

Device authorization lets a secondary client obtain access after the user approves a short user code in the browser or another logged-in session.

IDE / plugin flow

MethodDescription
MainApiV1StartDeviceAuthInitPostStart device authorization
MainApiV1StartDeviceAuthAuthorizePostAuthorize with user code
MainApiV1StartDeviceAuthPollGetPoll authorization status
deviceSession, _, err := client.DeviceAuthAPI.
MainApiV1StartDeviceAuthInitPost(context.Background()).
Execute()

authorizationBody := analogwakatime.NewMainApiV1StartDeviceAuthDesktopAgentAuthorizePostRequest(
"USER_CODE",
)
authorizedDevice, _, err := client.DeviceAuthAPI.
MainApiV1StartDeviceAuthAuthorizePost(ctx).
MainApiV1StartDeviceAuthDesktopAgentAuthorizePostRequest(*authorizationBody).
Execute()

deviceResult, _, err := client.DeviceAuthAPI.
MainApiV1StartDeviceAuthPollGet(context.Background()).
DeviceCode("DEVICE_CODE").
Execute()

Desktop-agent flow

initBody := analogwakatime.NewMainApiV1StartDeviceAuthDesktopAgentInitPostRequest()
agentSession, _, err := client.DeviceAuthAPI.
MainApiV1StartDeviceAuthDesktopAgentInitPost(context.Background()).
MainApiV1StartDeviceAuthDesktopAgentInitPostRequest(*initBody).
Execute()

authorizeBody := analogwakatime.NewMainApiV1StartDeviceAuthDesktopAgentAuthorizePostRequest(
"USER_CODE",
)
authorizedAgent, _, err := client.DeviceAuthAPI.
MainApiV1StartDeviceAuthDesktopAgentAuthorizePost(ctx).
MainApiV1StartDeviceAuthDesktopAgentAuthorizePostRequest(*authorizeBody).
Execute()

agentResult, _, err := client.DeviceAuthAPI.
MainApiV1StartDeviceAuthDesktopAgentPollGet(context.Background()).
DeviceCode("DEVICE_CODE").
Execute()

Android flow

androidSession, _, err := client.DeviceAuthAPI.
InitAndroidDeviceAuth(context.Background()).
Execute()

androidBody := analogwakatime.NewAuthorizeAndroidDeviceRequest("USER_CODE")
authorizedAndroid, _, err := client.DeviceAuthAPI.
AuthorizeAndroidDevice(ctx).
AuthorizeAndroidDeviceRequest(*androidBody).
Execute()

androidResult, _, err := client.DeviceAuthAPI.
PollAndroidDeviceAuth(context.Background()).
DeviceCode("DEVICE_CODE").
Execute()

Init and poll typically run without a user token. Authorize runs with an authenticated context.