packages/ember-simple-auth/addon/authenticators/oauth2-password-grant.js
/**
    Makes a request to the OAuth 2.0 server.

    @method makeRequest
    @param {String} url The request URL
    @param {Object} data The request data
    @param {Object} headers Additional headers to send in request
    @return {Promise} A promise that resolves with the response object
    @protected
  */
Makes a request to the OAuth 2.0 server.
Makes a request to the OAuth 2 . 0 server .
makeRequest(url, data, headers = {}) {
    headers['Content-Type'] = 'application/x-www-form-urlencoded';
    const clientId = this.get('clientId');
    if (!isEmpty(clientId)) {
      data['client_id'] = this.get('clientId');
    }
    const body = keys(data).map((key) => {
      return `${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`;
    }).join('&');
    const options = {
      body,
      headers,
      method: 'POST'
    };
    return new RSVP.Promise((resolve, reject) => {
      fetch(url, options).then((response) => {
        response.text().then((text) => {
          try {
            let json = JSON.parse(text);
            if (!response.ok) {
              response.responseJSON = json;
              reject(response);
            } else {
              resolve(json);
            }
          } catch (SyntaxError) {
            response.responseText = text;
            reject(response);
          }
        });
      }).catch(reject);
    });
  }
makeRequest ( url , data , headers = { } ) { headers [ 'Content-Type' ] = 'application/x-www-form-urlencoded' ; const clientId = this . get ( 'clientId' ) ; if ( ! isEmpty ( clientId ) ) { data [ 'client_id' ] = this . get ( 'clientId' ) ; } const body = keys ( data ) . map ( ( key ) => { return ` ${ encodeURIComponent ( key ) } ${ encodeURIComponent ( data [ key ] ) } ` ; } ) . join ( '&' ) ; const options = { body , headers , method : 'POST' } ; return new RSVP . Promise ( ( resolve , reject ) => { fetch ( url , options ) . then ( ( response ) => { response . text ( ) . then ( ( text ) => { try { let json = JSON . parse ( text ) ; if ( ! response . ok ) { response . responseJSON = json ; reject ( response ) ; } else { resolve ( json ) ; } } catch ( SyntaxError ) { response . responseText = text ; reject ( response ) ; } } ) ; } ) . catch ( reject ) ; } ) ; }
Makes a request to the OAuth 2.0 server.
Makes a request to the OAuth 2 . 0 server .