refs #125 Add misskey example and confirm authorization
This commit is contained in:
parent
7ed2fd2d63
commit
8324fce53e
1
example/typescript/package-lock.json
generated
1
example/typescript/package-lock.json
generated
|
@ -79,7 +79,6 @@
|
|||
"moment": "^2.24.0",
|
||||
"oauth": "^0.9.15",
|
||||
"socks-proxy-agent": "github:h3poteto/node-socks-proxy-agent#master",
|
||||
"typescript": "3.7.5",
|
||||
"ws": "^7.2.1"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
49
example/typescript/src/misskey/authorization.ts
Normal file
49
example/typescript/src/misskey/authorization.ts
Normal file
|
@ -0,0 +1,49 @@
|
|||
import * as readline from 'readline'
|
||||
import { OAuth, Misskey } from 'megalodon'
|
||||
|
||||
const rl: readline.ReadLine = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
})
|
||||
|
||||
const SCOPES: Array<string> = ['read', 'write', 'follow']
|
||||
const BASE_URL: string = 'https://misskey.io'
|
||||
|
||||
let clientId: string
|
||||
let clientSecret: string
|
||||
|
||||
const client = new Misskey(BASE_URL)
|
||||
|
||||
client
|
||||
.registerApp('Test App', {
|
||||
scopes: SCOPES
|
||||
})
|
||||
.then(appData => {
|
||||
clientId = appData.clientId
|
||||
clientSecret = appData.clientSecret
|
||||
console.log('\napp_secret_key:')
|
||||
console.log(clientSecret)
|
||||
console.log('Authorization URL is generated.')
|
||||
console.log(appData.url)
|
||||
console.log()
|
||||
return new Promise<string | null>(resolve => {
|
||||
rl.question('Enter any keys after you authorize to misskey: ', _code => {
|
||||
resolve(appData.session_token)
|
||||
rl.close()
|
||||
})
|
||||
})
|
||||
})
|
||||
.then((session_token: string | null) => {
|
||||
if (!session_token) {
|
||||
throw new Error('Could not get session token')
|
||||
}
|
||||
return client.fetchAccessToken(clientId, clientSecret, session_token, BASE_URL)
|
||||
})
|
||||
.then((tokenData: OAuth.TokenData) => {
|
||||
console.log('\naccess_token:')
|
||||
console.log(tokenData.accessToken)
|
||||
console.log('\nrefresh_token:')
|
||||
console.log(tokenData.refreshToken)
|
||||
console.log()
|
||||
})
|
||||
.catch((err: Error) => console.error(err))
|
|
@ -9,6 +9,7 @@ import { ProxyConfig } from './proxy_config'
|
|||
import generator, { MegalodonInterface } from './megalodon'
|
||||
import Mastodon from './mastodon'
|
||||
import Pleroma from './pleroma'
|
||||
import Misskey from './misskey'
|
||||
import Entity from './entity'
|
||||
|
||||
export {
|
||||
|
@ -24,6 +25,7 @@ export {
|
|||
MegalodonInterface,
|
||||
Mastodon,
|
||||
Pleroma,
|
||||
Misskey,
|
||||
Entity
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import MisskeyAPI from './misskey/api_client'
|
||||
import { NO_REDIRECT, DEFAULT_UA } from './default'
|
||||
import { DEFAULT_UA } from './default'
|
||||
import { ProxyConfig } from './proxy_config'
|
||||
import OAuth from './oauth'
|
||||
import Response from './response'
|
||||
|
@ -43,7 +43,7 @@ export default class Misskey {
|
|||
client_name: string,
|
||||
options: Partial<{ scopes: Array<string>; redirect_uris: string; website: string }> = {
|
||||
scopes: MisskeyAPI.DEFAULT_SCOPE,
|
||||
redirect_uris: NO_REDIRECT
|
||||
redirect_uris: this.baseUrl
|
||||
}
|
||||
): Promise<OAuth.AppData> {
|
||||
return this.createApp(client_name, options).then(async appData => {
|
||||
|
@ -66,10 +66,10 @@ export default class Misskey {
|
|||
client_name: string,
|
||||
options: Partial<{ scopes: Array<string>; redirect_uris: string; website: string }> = {
|
||||
scopes: MisskeyAPI.DEFAULT_SCOPE,
|
||||
redirect_uris: NO_REDIRECT
|
||||
redirect_uris: this.baseUrl
|
||||
}
|
||||
): Promise<OAuth.AppData> {
|
||||
const redirect_uris = options.redirect_uris || NO_REDIRECT
|
||||
const redirect_uris = options.redirect_uris || this.baseUrl
|
||||
const scopes = options.scopes || MisskeyAPI.DEFAULT_SCOPE
|
||||
|
||||
const params: {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import axios, { AxiosResponse, CancelTokenSource, AxiosRequestConfig } from 'axios'
|
||||
import { DEFAULT_UA } from '@/default'
|
||||
import proxyAgent, { ProxyConfig } from '@/proxy_config'
|
||||
import Response from '@/response'
|
||||
import { DEFAULT_UA } from '../default'
|
||||
import proxyAgent, { ProxyConfig } from '../proxy_config'
|
||||
import Response from '../response'
|
||||
import MisskeyEntity from './entity'
|
||||
import MegalodonEntity from '@/entity'
|
||||
import MegalodonEntity from '../entity'
|
||||
|
||||
namespace MisskeyAPI {
|
||||
export namespace Entity {
|
||||
|
|
Loading…
Reference in a new issue