How to use the whatwg-url.URLSearchParams function in whatwg-url

To help you get started, we’ve selected a few whatwg-url 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 tmrowco / tmrowapp-contrib / integrations / authentication / OAuthManager.js View on Github external
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 },
      )),
github amejia1 / atom-xterm / spec / atom-xterm-element-spec.js View on Github external
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()
    })
  })
github tmrowco / tmrowapp-contrib / integrations / authentication / objectToURLParams.js View on Github external
export default function (obj) {
  const body = new URLSearchParams();
  Object.keys(obj).forEach((k) => { body.append(k, obj[k]); });
  return body.toString();
}
github tmrowco / tmrowapp-contrib / integrations / authentication / OAuthManager.js View on Github external
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;
  }