pinafore/src/routes/_api/oauth.js
Nolan Lawson 4bd181d3cc
fix: update Sapper to latest (#775)
* fix: update to latest sapper

fixes #416

* fix error and debug pages

* requestIdleCallback makes column switching feel way nicer than double rAF

* add export feature

* add better csp info

* workaround for sapper sub-page issue

* clarify in readme about exporting

* fix now config

* switch from rIC to triple raf

* style-loader is no longer used

* update theming guide
2018-12-11 07:31:48 -08:00

38 lines
1.1 KiB
JavaScript

import { post, paramsString, WRITE_TIMEOUT } from '../_utils/ajax'
import { basename } from './utils'
const WEBSITE = 'https://pinafore.social'
const SCOPES = 'read write follow push'
const CLIENT_NAME = 'Pinafore'
export function registerApplication (instanceName, redirectUri) {
const url = `${basename(instanceName)}/api/v1/apps`
return post(url, {
client_name: CLIENT_NAME,
redirect_uris: redirectUri,
scopes: SCOPES,
website: WEBSITE
}, null, { timeout: WRITE_TIMEOUT })
}
export function generateAuthLink (instanceName, clientId, redirectUri) {
let params = paramsString({
'client_id': clientId,
'redirect_uri': redirectUri,
'response_type': 'code',
'scope': SCOPES
})
return `${basename(instanceName)}/oauth/authorize?${params}`
}
export function getAccessTokenFromAuthCode (instanceName, clientId, clientSecret, code, redirectUri) {
let url = `${basename(instanceName)}/oauth/token`
return post(url, {
client_id: clientId,
client_secret: clientSecret,
redirect_uri: redirectUri,
grant_type: 'authorization_code',
code: code
}, null, { timeout: WRITE_TIMEOUT })
}