Options
All
  • Public
  • Public/Protected
  • All
Menu

Initialize Auth:

const auth = Mal.auth("app_id")

Use initialized Auth to login:

  • Unoffical way to login (not recomended) {@link Auth.Unstable.login}
    const acount = await auth.Unstable.login("username","password");
    
  • Offical way to login (recomended) Auth.authorizeWithCode
  • Generate pkce (in this example pkce-challenge npm package is used)
    import pkceChallenge from "pkce-challenge";
    const pkce = pkceChallenge();
  • Get OAuth url Auth.getOAuthUrl
    const url = auth.getOAuthUrl(pkce.code_challenge);
    
  • Open returned url, accept oauth and use returned code to authorize Auth.authorizeWithCode
    const acount = await auth.authorizeWithCode(code, code_challenge)
    

You probably want to save acount somewhere, you can just call acount.stringifyToken() to get json

Later you can load it using:

const token = Mal.MalToken.fromJsonString(jsonStr);
const acount = auth.loadToken(token);

If more time has passed you can also refresh token instead of loading last one

const acount = await auth.authorizeWithRefreshToken(json.refresh_token);

Done, you can use MalAcount

Hierarchy

  • Auth

Index

Constructors

  • new Auth(clientId: string): Auth

Properties

Unstable: { login: (username: string, password: string) => Promise<MalAcount> } = ...

Undocumented Endpoints, those can disperse at any moment

Type declaration

  • login: (username: string, password: string) => Promise<MalAcount>
      • (username: string, password: string): Promise<MalAcount>
      • This endpoint makes the whole idea of OAuth API pointless, so it will probably be removed soonish (EDIT: 4 years have passed it's still here)

        Example of paradox related to this endpoint is that you can use someone's app id to get access to API. So basically it allows you to go around API request limits

        (works reliably since 2018) `(2022 still works fine!)

        Parameters

        • username: string
        • password: string

        Returns Promise<MalAcount>

clientId: string

Methods

  • authorizeWithCode(code: string, codeChallenge: string): Promise<MalAcount>
  • authorizeWithRefreshToken(refreshToken: string): Promise<MalAcount>
  • getOAuthUrl(codeChallenge: string): string

Generated using TypeDoc