Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

Getting User Info JavaScript Examples

When you get an access token via headless registration or headless login, you can retrieve user information with a request to the User Info endpoint. Use this example to understand how.

In this example, the access token is passed in an Authorization Bearer header.

1function getUserInfo(accessToken) {
2    client = new XMLHttpRequest();
3    client.open("GET", expDomain + userInfoURI, true);
4    client.setRequestHeader("Content-Type", "application/json");
5    client.setRequestHeader("Authorization", 'Bearer '  + accessToken);
6    client.send(); 
7
8    client.onreadystatechange = function() {
9        if(this.readyState == 4) {
10            if (this.status == 200) {
11                //User Info response
12                console.log(client.response);
13            } else {
14                console.log(client.response)
15                onError("An Error Occured during Forgot Password Step: " + forgotPasswordProcessStep, client.response); 
16            }
17        } 
18    }
19}