@design-sdk/figma-oauth
Version:
OAuth management for figma
71 lines (69 loc) • 2.56 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.request = exports.refreshOauthToken = exports.requestOauthToken = void 0;
const axios_1 = __importDefault(require("axios"));
const urls_1 = require("./urls");
/**
* The format of the response body is:
* ```json
* {
"access_token": "<TOKEN>",
"expires_in": "<EXPIRATION (in seconds)>",
"refresh_token": "<REFRESH TOKEN>"
}
* ```
*/
function requestOauthToken({ client_id, client_secret, grant_type = "authorization_code", redirect_uri, code, }) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield axios_1.default.post((0, urls_1.oauthTokenRequestUrl)({
client_id,
client_secret,
redirect_uri,
grant_type,
code,
}));
return res.data;
});
}
exports.requestOauthToken = requestOauthToken;
/**
* [Refreshing OAuth tokens](https://www.figma.com/developers/api#refresh-oauth2)
*
* ```
POST https://www.figma.com/api/oauth/refresh?
client_id=:client_id&
client_secret=:client_secret&
refresh_token=:refresh_token
{
"access_token": <TOKEN>,
"expires_in": <EXPIRATION (in seconds)>,
}
* ```
*/
function refreshOauthToken({ client_id, client_secret, refresh_token, }) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield axios_1.default.post((0, urls_1.oauthTokenRefreshUrl)({
client_id,
client_secret,
refresh_token,
}));
return res.data;
});
}
exports.refreshOauthToken = refreshOauthToken;
exports.request = {
authentication: requestOauthToken,
tokenrefresh: refreshOauthToken,
};