Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async authorize(openUrlAndWaitForCallback) {
// Step 1 - get request token
const method = 'POST';
let req = {
method,
body: objectToURLParams(this.oauth.authorize({ url: this.requestTokenUrl, method, data: {} })),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
};
let res = await fetch(this.requestTokenUrl, req);
if (!res.ok) {
const text = await res.text();
throw new HTTPError(text, res.status);
}
let resultParams = new URLSearchParams(await res.text());
const oauthToken = resultParams.get('oauth_token');
const oauthTokenSecret = resultParams.get('oauth_token_secret');
// Step 2 - open window to get autorization credentials
await openUrlAndWaitForCallback(
`${this.authorizeUrl}?oauth_token=${oauthToken}&oauth_callback=${getCallbackUrl()}`,
getCallbackUrl()
);
// Step 3 - Obtain an access token
req = {
method,
body: objectToURLParams(this.oauth.authorize(
{ url: this.accessTokenUrl, method, data: {} },
{ key: oauthToken, secret: oauthTokenSecret },
)),
it('leaveOpenAfterExit() true set in uri', (done) => {
let expected = true
let params = new URLSearchParams({'leaveOpenAfterExit': expected})
let url = new URL('atom-xterm://?' + params.toString())
createNewElement(url.href).then((element) => {
expect(element.leaveOpenAfterExit()).toBe(expected)
done()
})
})
export default function (obj) {
const body = new URLSearchParams();
Object.keys(obj).forEach((k) => { body.append(k, obj[k]); });
return body.toString();
}
req = {
method,
body: objectToURLParams(this.oauth.authorize(
{ url: this.accessTokenUrl, method, data: {} },
{ key: oauthToken, secret: oauthTokenSecret },
)),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
};
res = await fetch(this.accessTokenUrl, req);
if (!res.ok) {
const text = await res.text();
throw new HTTPError(text, res.status);
}
resultParams = new URLSearchParams(await res.text());
this.state.oauthToken = resultParams.get('oauth_token');
this.state.oauthTokenSecret = resultParams.get('oauth_token_secret');
return this.state;
}