Skip to content

Commit

Permalink
Getting additional fields from identity end point
Browse files Browse the repository at this point in the history
  • Loading branch information
wmathurin committed Mar 27, 2019
1 parent 07cd382 commit 492108a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
7 changes: 7 additions & 0 deletions credshelper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ $ npm i
$ npm start

```
Make sure CORS policy is disabled (*) in you browser if you want test_credentials.json to include identity data needed by Android tests.

In a browser, open `http://localhost:8080`, enter credentials.

Copy the test credentials to your `test_credentials.json` file!


(*) On chrome install https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi or run chrome --disable-web-security


52 changes: 41 additions & 11 deletions credshelper/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,51 @@
return obj;
}

// Get identity data
function getIdentityData(identityUrl, accessToken, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', identityUrl, true);
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Authorization", "Bearer " + accessToken);
xhr.setRequestHeader('Cache-Control', 'no-store');

xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status > 199 && xhr.status < 300) {
callback(JSON.parse(xhr.responseText));
} else {
console.error("Failed to get identity data");
callback({});
}
}
};

xhr.send();
}

// Build json for test_credentials.json and display it
function createTestCredentials(auth) {

var testCredentials =
{
"test_redirect_uri" : config.oauthCallbackURL,
"access_token" : "__NOT_REQUIRED__",
"instance_url" : auth.instance_url,
"identity_url" : auth.id,
"refresh_token" : auth.refresh_token,
"test_client_id" : config.appId,
"test_login_domain" : config.loginURL
};
getIdentityData(auth.id, auth.access_token, function(identityData) {

writeJson(testCredentials);
var testCredentials =
{
"test_redirect_uri" : config.oauthCallbackURL,
"access_token" : "__NOT_REQUIRED__",
"instance_url" : auth.instance_url,
"identity_url" : auth.id,
"refresh_token" : auth.refresh_token,
"test_client_id" : config.appId,
"test_login_domain" : config.loginURL,
"organization_id": identityData.organization_id,
"username": identityData.username,
"user_id": identityData.user_id,
"display_name": identityData.display_name,
"photo_url": identityData.photos? identityData.photos.picture : undefined
};

writeJson(testCredentials);
});
}

// Helper to write to html document
Expand Down

0 comments on commit 492108a

Please sign in to comment.