How to use the megalodon.fetchAccessToken function in megalodon

To help you get started, we’ve selected a few megalodon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github h3poteto / megalodon / example / typescript / authorization.ts View on Github external
}).then((code: string) => {
  return Mastodon.fetchAccessToken(clientId, clientSecret, code, BASE_URL)
})
  .then((tokenData: OAuth.TokenData) => {
github cutls / TheDesk / src / main / Auth.ts View on Github external
private static async auth(event: Event, code: string, instance: string, clientId: string, clientSecret: string, redirectUri: string) {
    let tokenData: Partial<{ accessToken: string }>
    try {
      tokenData = await Mastodon.fetchAccessToken(clientId, clientSecret, code, "https://" + instance, redirectUri)
    } catch (err) {
      let error: Error = err
      error.name = "ERROR_CONNECTION"
      event.sender.send(`login-complete`, undefined, error)
      return
    }

    if (tokenData.accessToken === undefined) {
      let error = new Error("Failed to get access token.")
      error.name = "ERROR_GET_TOKEN"
      event.sender.send(`login-complete`, undefined, error)
      return
    }

    const client = Client.createAuthClient('http', instance, tokenData.accessToken)
github h3poteto / whalebird-desktop / src / main / auth.ts View on Github external
async getAccessToken(code: string, proxy: ProxyConfig | false): Promise {
    const tokenData: OAuth.TokenData = await Mastodon.fetchAccessToken(
      this.clientId,
      this.clientSecret,
      code,
      this.baseURL,
      'urn:ietf:wg:oauth:2.0:oob',
      proxy
    )
    const search = {
      baseURL: this.baseURL,
      domain: this.domain,
      clientId: this.clientId,
      clientSecret: this.clientSecret
    }
    const rec = await this.db.searchAccount(search)
    const accessToken = tokenData.accessToken
    const refreshToken = tokenData.refreshToken

megalodon

Fediverse API client for node.js and browser

MIT
Latest version published 17 days ago

Package Health Score

75 / 100
Full package analysis