Client for the MyMagti API.
Currently provides fetchToken and the other OAuth helpers for obtaining and refreshing OAuth tokens by mimicking the mobile app requests. You can swap the fetch implementation for testing.
Mocking fetch for tests
Mocking fetch for tests
import { assertEquals } from "@std/assert"; import { fetchToken } from "@hertzg/mymagti-api"; const mockFetch: typeof fetch = async (_url, _init) => new Response( JSON.stringify({ access_token: "A", autoLogin: 0, expires_in: 3600, jti: "id", phoneNo: "5xxxxxxxx", refresh_token: "R", scope: "*", token_type: "bearer", userId: 1, userIdentifier: "u", }), { status: 200, headers: { "content-type": "application/json" } }, ); const res = await fetchToken( { type: "login", username: "u", password: "p" }, { fetch: mockFetch }, ); assertEquals(res.result, "success"); if (res.result === "success") { assertEquals(typeof res.data.access_token, "string"); }
f
fetchToken(): Promise<LoginResult>
request: FetchTokenRequest,
options?: FetchOauthOptions
Fetches an OAuth token using the provided request.
I
GenericErrorResponse
Generic error response from OAuth server.
-
error: string
Error code
-
error_description: string
Error description
I
TokenInfo
OAuth token information.
-
access_token: string
Access token for API requests
-
autoLogin: number
Auto-login flag
-
expires_in: number
Token expiration time in seconds
-
jti: string
JWT ID
-
phoneNo: string
Phone number
-
refresh_token: string
Refresh token for getting new access tokens
-
scope: string
Token scope
-
token_type: string
Token type
-
userId: number
User ID
-
userIdentifier: string
User identifier
T
T
FetchTokenRequest =
{ type: "login"; username: string; password: string; }
| { type: "refresh"; refreshToken: string; }
| { type: "refresh"; refreshToken: string; }
Request type for fetching OAuth tokens.
T
v
DEFAULT_BASE_URL: "https://oauth.magticom.ge/auth/"
OAuth helpers for MyMagti API.
v
DEFAULT_USER_AGENT: "MyMagti/11.9.96 (Magticom.MyMagti; build:1; iOS 18.1.0) Alamofire/5.9.1"
Default user agent string for OAuth requests.
Usage
import * as mod from "mod.ts";