How to use the megalodon.registerApp 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
import * as readline from 'readline'
import Mastodon, { OAuth } from 'megalodon'

const rl: readline.ReadLine = readline.createInterface({
  input: process.stdin,
  output: process.stdout
})

const SCOPES: string = 'read write follow'
const BASE_URL: string = 'https://mastodon.social'

let clientId: string
let clientSecret: string

Mastodon.registerApp('Test App', {
  scopes: SCOPES
}, BASE_URL).then(appData => {
  clientId = appData.clientId
  clientSecret = appData.clientSecret
  console.log('Authorization URL is generated.')
  console.log(appData.url)
  console.log()
  return new Promise(resolve => {
    rl.question('Enter the authorization code from website: ', code => {
      resolve(code)
      rl.close()
    })
  })
}).then((code: string) => {
  return Mastodon.fetchAccessToken(clientId, clientSecret, code, BASE_URL)
})
github h3poteto / whalebird-desktop / src / main / auth.ts View on Github external
async getAuthorizationUrl(domain = 'mastodon.social', proxy: ProxyConfig | false): Promise {
    this.setOtherInstance(domain)
    const res = await Mastodon.registerApp(
      appName,
      {
        scopes: scope,
        website: appURL
      },
      this.baseURL,
      proxy
    )
    this.clientId = res.clientId
    this.clientSecret = res.clientSecret

    const order = await this.db
      .lastAccount()
      .then(account => account.order + 1)
      .catch(err => {
        console.log(err)
github cutls / TheDesk / src / main / Auth.ts View on Github external
private static async setup(event: Event, instance: string, useURLScheme: boolean) {
    let appData: OAuth.AppData

    try {
      let options: Partial<{ scopes: string, redirect_uris: string, website: string }> = {
        scopes: "read write follow",
        website: "https://thedesk.top",
      }
      if (useURLScheme) {
        options.redirect_uris = this.redirectUri
      }
      appData = await Mastodon.registerApp(
        "TheDesk",
        options,
        "https://" + instance
      )
    } catch (err) {
      let error: Error = err
      event.sender.send(`error`, {
        id: "ERROR_CONNECTION",
        message: "Connection error",
        meta: error
      })
      return
    }

    let url: string | null = appData.url
    if (url === null) {

megalodon

Fediverse API client for node.js and browser

MIT
Latest version published 17 days ago

Package Health Score

75 / 100
Full package analysis