Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Download Postman - https://www.postman.com/

  2. Run it

  3. Create a new request:

...

    ...

    titleExample
    1. Choose method POST and enter the URL:

    Code Block
    https://{{authService}}/api/v2/OpenId/service/

    ...

    Expand
    titleExample
    Code Block
    https://{{authService}}/api/v2/OpenId/service/
    1. Copy the Pre-request Script and configure user, password and pbxHost:

    Code Block
    const user = 'extension';
    const pass = 'password';
    const pbxHost = 'https://<domain>.wildixin.com';
    
    const authService = 'auth.wildix.com';
    pm.variables.set('authService', authService);
    
    pm.sendRequest({
        url: `${pbxHost}/api/v1/personal/token/?service=${authService}`,
        method: 'GET',
        header: {
            'Authorization': 'Basic ' + btoa(`${user}:${pass}`)
        },
        body: {}
    }, function(err, response) {
        if (err || response.code !== 200) {
            throw new Error('Personal token not received');
        }
        const personalToken = response.json().result.token;
        console.log('PERSONAL TOKEN', personalToken);
    
        pm.sendRequest({
            url: `https://${authService}/api/v2/Token/`,
            method: 'GET',
            header: {
                'Authorization': `Bearer ${personalToken}`
            },
            body: {}
        }, function(err, response) {
            if (err || response.code !== 200) {
                throw new Error('Access token for auth not received');
            }
    
            const authAccessUserToken = response.json().result.accessToken;
            console.log('AUTH ACCESS USER TOKEN', authAccessUserToken);
            pm.variables.set('authAccessUserToken', authAccessUserToken);
        });
    });
    Expand
    titlePre-request Script
    Code Block
    const user = 'extension';
    const pass = 'password';
    const pbxHost = 'https://<domain>.wildixin.com';
    
    const authService = 'auth.wildix.com';
    pm.variables.set('authService', authService);
    
    pm.sendRequest({
        url: `${pbxHost}/api/v1/personal/token/?service=${authService}`,
        method: 'GET',
        header: {
            'Authorization': 'Basic ' + btoa(`${user}:${pass}`)
        },
        body: {}
    }, function(err, response) {
        if (err || response.code !== 200) {
            throw new Error('Personal token not received');
        }
        const personalToken = response.json().result.token;
        console.log('PERSONAL TOKEN', personalToken);
    
        pm.sendRequest({
            url: `https://${authService}/api/v2/Token/`,
            method: 'GET',
            header: {
                'Authorization': `Bearer ${personalToken}`
            },
            body: {}
        }, function(err, response) {
            if (err || response.code !== 200) {
                throw new Error('Access token for auth not received');
            }
    
            const authAccessUserToken = response.json().result.accessToken;
            console.log('AUTH ACCESS USER TOKEN', authAccessUserToken);
            pm.variables.set('authAccessUserToken', authAccessUserToken);
        });
    });

    1. Insert script to Postman:

      Image Added
    Expand
    titleExample
    1. Go to the Authorization tab and choose the type and set dynamic variable:

    Code Block
    {{authAccessUserToken}}

    ...

    Expand
    titleExample
    Code Block
    {{authAccessUserToken}}

    1. Configure payload, see aud and scope in the documentation for services

      Code Block
      {
          "aud": "https://api.x-bees.com",
          "scope": "xbees"
      }
    2. Insert payload to request:

      Image Added
    Expand
    titleExample

    1. Make a request and receive a token:

      Image Added
    Expand
    titleExample