---
schema_version: "1"
id: 955ba49611affed9dc017494766283d86aa3829d1a486974eda99bb3961584a1
title: AuthProviderPluginClass Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_class_Auth_AuthProviderPluginClass.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Auth_AuthProviderPluginClass.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 52f55b07d2611bad807be3e83d8c43c36f9170783df2fab2ec9b4af39d607b7d
description: Contains methods to create a custom OAuth-based authentication provider plug-in for single sign-on in to Salesforce. Use this class to create a custom authentication provider plug-in if you can’t use one of the authentication providers that Salesforce provides. Returns the custom metadata type API name for a custom OAuth-based authentication provider for single sign-on to Salesforce. Returns information from the custom authentication provider about the current user. This information is used by the registration handler and in other authentication provider flows. Uses the authentication provider’s supported authentication protocol to return an OAuth access token, OAuth secret or refresh token, and the state passed in when the request for the current user was initiated. Returns the URL where the user is redirected for authentication. Returns a new access token, which is used to update an expired access token.
---
# AuthProviderPluginClass Class

Contains methods to create a custom OAuth-based authentication provider plug-in for single sign-on in to Salesforce. Use this class to create a custom authentication provider plug-in if you can’t use one of the authentication providers that Salesforce provides.

## Namespace

[Auth](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_Auth.htm "The Auth namespace provides an interface and classes for single sign-on into Salesforce and session security management.")

## Usage

To create a custom authentication provider for single sign-on, create a class that extends Auth.AuthProviderPluginClass. This class allows you to store the custom configuration for your authentication provider and handle authentication protocols when users log in to Salesforce with their login credentials for an external service provider. In Salesforce, the class that implements this interface appears in the Provider Type drop-down list in Auth. Providers in Setup. Make sure that the user you specify to run the class has “Customize Application” and “Manage Auth. Providers” permissions.

As of API version 39.0, use the abstract class AuthProviderPluginClass to create a custom external authentication provider. This class replaces the AuthProviderPlugin interface. If you’ve already implemented a custom authentication provider plug-in using the interface, it still works. However, use AuthProviderPluginClass to extend your plug-in. If you haven’t created an interface, create a custom authentication provider plug-in by extending this abstract class. For more information, see [Create a Custom Authentication Provider Plug-in](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexcode.meta/apexcode/authproviderplugin.htm).

- **[AuthProviderPluginClass Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Auth_AuthProviderPluginClass.htm#apex_Auth_AuthProviderPluginClass_methods)**
- **[AuthProviderPluginClass Code Example](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Auth_AuthProviderPluginClass.htm#apex_Auth_AuthProviderPluginClass_example)**

## AuthProviderPluginClass Methods

The AuthProviderPluginClass methods don’t support DML options.

This class doesn't include a method for single logout. You can easily configure single logout in Setup. For steps, see [Configure OpenID Connect Single Logout with Salesforce as the Relying Party](https://help.salesforce.com/s/articleView?id=xcloud.security_auth_slo_oidc_rp_configuring.htm&language=en_US) in Salesforce Help. Alternatively, create custom methods for single logout.

- **[getCustomMetadataType()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Auth_AuthProviderPluginClass.htm#apex_Auth_AuthProviderPluginClass_getCustomMetadataType)**  
    Returns the custom metadata type API name for a custom OAuth-based authentication provider for single sign-on to Salesforce.
- **[getUserInfo(authProviderConfiguration, response)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Auth_AuthProviderPluginClass.htm#apex_Auth_AuthProviderPluginClass_getUserInfo)**  
    Returns information from the custom authentication provider about the current user. This information is used by the registration handler and in other authentication provider flows.
- **[handleCallback(authProviderConfiguration, callbackState)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Auth_AuthProviderPluginClass.htm#apex_Auth_AuthProviderPluginClass_handleCallback)**  
    Uses the authentication provider’s supported authentication protocol to return an OAuth access token, OAuth secret or refresh token, and the state passed in when the request for the current user was initiated.
- **[initiate(authProviderConfiguration, stateToPropagate)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Auth_AuthProviderPluginClass.htm#apex_Auth_AuthProviderPluginClass_initiate)**  
    Returns the URL where the user is redirected for authentication.
- **[refresh(authProviderConfiguration, refreshToken)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Auth_AuthProviderPluginClass.htm#apex_Auth_AuthProviderPluginClass_refresh)**  
    Returns a new access token, which is used to update an expired access token.

### getCustomMetadataType()

Returns the custom metadata type API name for a custom OAuth-based authentication provider for single sign-on to Salesforce.

#### Signature

public String getCustomMetadataType()

#### Return Value

Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")

The custom metadata type API name for the authentication provider.

#### Usage

The getCustomMetatadaType() method returns only custom metadata type names. It does not return custom metadata record names. As of API version 39.0, use this method when extending Auth.AuthProviderPluginClass to create a custom external authentication provider.

### getUserInfo(authProviderConfiguration, response)

Returns information from the custom authentication provider about the current user. This information is used by the registration handler and in other authentication provider flows.

#### Signature

public Auth.UserData getUserInfo(Map<String,String\> authProviderConfiguration, Auth.AuthProviderTokenResponse response)

#### Parameters

- **authProviderConfiguration**:
    
    Type: [Map](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_map.htm#apex_methods_system_map "Contains methods for the Map collection type.")<[String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type."),[String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")\>
    
    The configuration for the custom authentication provider. When you create a custom metadata type in Salesforce, the configuration populates it with the custom metadata type default values. Or you can set the configuration with values that you enter when you create the custom provider in Auth. Providers in Setup.
- **response**:
    
    Type: [Auth.AuthProviderTokenResponse](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Auth_AuthProviderTokenResponse.htm#apex_class_Auth_AuthProviderTokenResponse "Stores the response from the AuthProviderPlugin.handleCallback method.")
    
    The OAuth access token, OAuth secret or refresh token, and state provided by the authentication provider to authenticate the current user.

#### Return Value

Type: [Auth.UserData](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Auth_UserData.htm#apex_Auth_UserData_ctor "Creates a new instance of the Auth.UserData class using the specified arguments.")

Creates a new instance of the Auth.UserData class.

#### Usage

As of API version 39.0, use this method when extending Auth.AuthProviderPluginClass to create a custom authentication provider.

### handleCallback(authProviderConfiguration, callbackState)

Uses the authentication provider’s supported authentication protocol to return an OAuth access token, OAuth secret or refresh token, and the state passed in when the request for the current user was initiated.

#### Signature

public Auth.AuthProviderTokenResponse handleCallback(Map<String,String\> authProviderConfiguration, Auth.AuthProviderCallbackState callbackState)

#### Parameters

- **authProviderConfiguration**:
    
    Type: [Map](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_map.htm#apex_methods_system_map "Contains methods for the Map collection type.")<[String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")[String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")\>
    
    The configuration for the custom authentication provider. When you create a custom metadata type in Salesforce, the configuration populates with the custom metadata type default values. Or you can set the configuration with values you enter when you create the custom provider in Auth. Providers in Setup.
- **callbackState**:
    
    Type: [Auth.AuthProviderCallbackState](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Auth_AuthProviderCallbackState.htm#apex_class_Auth_AuthProviderCallbackState "Provides request HTTP headers, body, and query parameters to the AuthProviderPlugin.handleCallback method for user authentication. This class allows you to group the information passed in rather than passing headers, body, and query parameters individually.")
    
    The class that contains the HTTP headers, body, and queryParams of the authentication request.

#### Return Value

Type: [Auth.AuthProviderTokenResponse](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Auth_AuthProviderTokenResponse.htm#apex_class_Auth_AuthProviderTokenResponse "Stores the response from the AuthProviderPlugin.handleCallback method.")

Creates an instance of the AuthProviderTokenResponse class.

#### Usage

As of API version 39.0, use this method when extending Auth.AuthProviderPluginClass to create a custom authentication provider.

### initiate(authProviderConfiguration, stateToPropagate)

Returns the URL where the user is redirected for authentication.

#### Signature

public System.PageReference initiate(Map<String,String\> authProviderConfiguration, String stateToPropagate)

#### Parameters

- **authProviderConfiguration**:
    
    Type: [Map](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_map.htm#apex_methods_system_map "Contains methods for the Map collection type.")<[String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")[String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")\>
    
    The configuration for the custom authentication provider. When you create a custom metadata type in Salesforce, the configuration populates with the custom metadata type default values. Or you can set the configuration with values you enter when you create the custom provider in Auth. Providers in Setup.
- **stateToPropagate**:
    
    Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")
    
    The state passed in to initiate the authentication request for the user.

#### Return Value

Type: [System.PageReference](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_system_pagereference.htm#apex_system_pagereference "A PageReference is a reference to an instantiation of a page. Among other attributes, PageReferences consist of a URL and a set of query parameter names and values.")

The URL of the page where the user is redirected for authentication.

#### Usage

As of API version 39.0, use this method when extending Auth.AuthProviderPluginClass to create a custom authentication provider.

### refresh(authProviderConfiguration, refreshToken)

Returns a new access token, which is used to update an expired access token.

#### Signature

public Auth.OAuthRefreshResult refresh(Map<String,String\> authProviderConfiguration, String refreshToken)

#### Parameters

- **authProviderConfiguration**:
    
    Type: [Map](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_map.htm#apex_methods_system_map "Contains methods for the Map collection type.")<[String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type."),[String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")\>
    
    The configuration for the custom authentication provider. When you create a custom metadata type in Salesforce, the configuration populates with the custom metadata type default values. Or you can set the configuration with values you enter when you create the custom provider in Auth. Providers in Setup.
- **refreshToken**:
    
    Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")
    
    The refresh token for the user who is logged in.

#### Return Value

Type: Auth.OAuthRefreshResult

Returns the new access token, or an error message if an error occurs.

#### Usage

A successful request returns a Auth.OAuthRefreshResult with the access token and refresh token in the response. If you receive an error, make sure that you set the error string to the error message. A NULL error string indicates no error.

The refresh method works only with named credentials; it doesn’t respect the standard OAuth refresh flow. The refresh method with named credentials works only if the earlier request returns a 401.

## AuthProviderPluginClass Code Example

The following example demonstrates how to implement a custom Auth. provider plug-in using the abstract class, Auth.AuthProviderPluginClass.

public with sharing class Concur extends Auth.AuthProviderPluginClass {

    // Use this URL for the endpoint that the
    // authentication provider calls back to for configuration.
    public String redirectUrl;
    private String key;
    private String secret;

    // Application redirection to the Concur website for
    // authentication and authorization.
    private String authUrl;

    // URI to get the new access token from concur using the GET verb.
    private String accessTokenUrl;

    // Api name for the custom metadata type created for this auth provider.
    private String customMetadataTypeApiName;

    // Api URL to access the user in Concur
    private String userAPIUrl;

    // Version of the user api URL to access data from Concur
    private String userAPIVersionUrl;

    public String getCustomMetadataType() {
        return customMetadataTypeApiName;
    }

    public PageReference initiate(Map<string,string>
        authProviderConfiguration, String stateToPropagate) {
        authUrl = authProviderConfiguration.get('Auth\_Url\_\_c');
        key = authProviderConfiguration.get('Key\_\_c');

        // Here the developer can build up a request of some sort.
        // Ultimately, they return a URL where we will redirect the user.
        String url = authUrl + '?client\_id='\+ key +'&scope=USER,EXPRPT,LIST&redirect\_uri='\+ redirectUrl + '&state=' + stateToPropagate;
        return new PageReference(url);
    }

    public Auth.AuthProviderTokenResponse handleCallback(Map<string,string>
        authProviderConfiguration, Auth.AuthProviderCallbackState state ) {
        // Here, the developer will get the callback with actual protocol.
        // Their responsibility is to return a new object called
        // AuthProviderTokenResponse.
        // This will contain an optional accessToken and refreshToken
        key = authProviderConfiguration.get('Key\_\_c');
        secret = authProviderConfiguration.get('Secret\_\_c');
        accessTokenUrl = authProviderConfiguration.get('Access\_Token\_Url\_\_c');

        Map<String,String\> queryParams = state.queryParameters;
        String code = queryParams.get('code');
        String sfdcState = queryParams.get('state');

        HttpRequest req = new HttpRequest();
        String url = accessTokenUrl+'?code=' + code + '&client\_id=' + key +
            '&client\_secret=' + secret;
        req.setEndpoint(url);
        req.setHeader('Content-Type','application/xml');
        req.setMethod('GET');

        Http http = new Http();
        HTTPResponse res = http.send(req);
        String responseBody = res.getBody();
        String token = getTokenValueFromResponse(responseBody, 'Token', null);

        return new Auth.AuthProviderTokenResponse('Concur', token,
            'refreshToken', sfdcState);
    }

    public Auth.UserData getUserInfo(Map<string,string>
        authProviderConfiguration,
        Auth.AuthProviderTokenResponse response) {
        //Here the developer is responsible for constructing an
        //Auth.UserData object
        String token = response.oauthToken;
        HttpRequest req = new HttpRequest();
        userAPIUrl = authProviderConfiguration.get('API\_User\_Url\_\_c');
        userAPIVersionUrl = authProviderConfiguration.get
            ('API\_User\_Version\_Url\_\_c');
        req.setHeader('Authorization', 'OAuth ' + token);
        req.setEndpoint(userAPIUrl);
        req.setHeader('Content-Type','application/xml');
        req.setMethod('GET');

        Http http = new Http();
        HTTPResponse res = http.send(req);
        String responseBody = res.getBody();
        String id = getTokenValueFromResponse(responseBody,
            'LoginId',userAPIVersionUrl);
        String fname = getTokenValueFromResponse(responseBody,
            'FirstName', userAPIVersionUrl);
        String lname = getTokenValueFromResponse(responseBody,
            'LastName', userAPIVersionUrl);
        String flname = fname + ' ' + lname;
        String uname = getTokenValueFromResponse(responseBody,
            'EmailAddress', userAPIVersionUrl);
        String locale = getTokenValueFromResponse(responseBody,
            'LocaleName', userAPIVersionUrl);
        Map<String,String\> provMap = new Map<String,String\>();
        provMap.put('what1', 'noidea1');
        provMap.put('what2', 'noidea2');
        return new Auth.UserData(id, fname, lname, flname,
            uname, 'what', locale, null, 'Concur', null, provMap);
    }

    private String getTokenValueFromResponse(String response,
        String token, String ns) {
        Dom.Document docx = new Dom.Document();
        docx.load(response);
        String ret = null;

        dom.XmlNode xroot = docx.getrootelement() ;
        if(xroot != null){
            ret = xroot.getChildElement(token, ns).getText();
        }
        return ret;
    }

}

### Sample Test Classes

The following example contains test classes for the Concur class.

@IsTest
public with sharing class ConcurTestClass {

    private static final String OAUTH\_TOKEN = 'testToken';
    private static final String STATE = 'mocktestState';
    private static final String REFRESH\_TOKEN = 'refreshToken';
    private static final String LOGIN\_ID = 'testLoginId';
    private static final String USERNAME = 'testUsername';
    private static final String FIRST\_NAME = 'testFirstName';
    private static final String LAST\_NAME = 'testLastName';
    private static final String EMAIL\_ADDRESS = 'testEmailAddress';
    private static final String LOCALE\_NAME = 'testLocalName';
    private static final String FULL\_NAME = FIRST\_NAME + ' ' + LAST\_NAME;
    private static final String PROVIDER = 'Concur';
    private static final String REDIRECT\_URL =
        'http://localhost/services/authcallback/orgId/Concur';
    private static final String KEY = 'testKey';
    private static final String SECRET = 'testSecret';
    private static final String STATE\_TO\_PROPOGATE = 'testState';
    private static final String ACCESS\_TOKEN\_URL =
        'http://www.dummyhost.com/accessTokenUri';
    private static final String API\_USER\_VERSION\_URL =
        'http://www.dummyhost.com/user/20/1';
    private static final String AUTH\_URL =
        'http://www.dummy.com/authurl';
    private static final String API\_USER\_URL =
        'www.concursolutions.com/user/api';

    // In the real world scenario, the key and value would be read
    // from the (custom fields in) custom metadata type record.
    private static Map<String,String\> setupAuthProviderConfig () {
        Map<String,String\> authProviderConfiguration = new Map<String,String\>();
        authProviderConfiguration.put('Key\_\_c', KEY);
        authProviderConfiguration.put('Auth\_Url\_\_c', AUTH\_URL);
        authProviderConfiguration.put('Secret\_\_c', SECRET);
        authProviderConfiguration.put('Access\_Token\_Url\_\_c', ACCESS\_TOKEN\_URL);
        authProviderConfiguration.put('API\_User\_Url\_\_c',API\_USER\_URL);
        authProviderConfiguration.put('API\_User\_Version\_Url\_\_c',
            API\_USER\_VERSION\_URL);
        authProviderConfiguration.put('Redirect\_Url\_\_c',REDIRECT\_URL);
        return authProviderConfiguration;
    }

    @IsTest
    static void testInitiateMethod() {
        String stateToPropogate = 'mocktestState';
        Map<String,String\> authProviderConfiguration = setupAuthProviderConfig();
        Concur concurCls = new Concur();
        concurCls.redirectUrl = authProviderConfiguration.get('Redirect\_Url\_\_c');
        PageReference expectedUrl = new PageReference(authProviderConfiguration.get('Auth\_Url\_\_c') + '?client\_id='+
            authProviderConfiguration.get('Key\_\_c') +'&scope=USER,EXPRPT,LIST&redirect\_uri='+
            authProviderConfiguration.get('Redirect\_Url\_\_c') + '&state=' +
            STATE\_TO\_PROPOGATE);
        PageReference actualUrl = concurCls.initiate(authProviderConfiguration, STATE\_TO\_PROPOGATE);
        Assert.areEqual(expectedUrl.getUrl(), actualUrl.getUrl());
    }

    @IsTest
    static void testHandleCallback() {
        Map<String,String\> authProviderConfiguration =
            setupAuthProviderConfig();
        Concur concurCls = new Concur();
        concurCls.redirectUrl = authProviderConfiguration.get
            ('Redirect\_Url\_c');

        Test.setMock(HttpCalloutMock.class, new
            ConcurMockHttpResponseGenerator());

        Map<String,String\> queryParams = new Map<String,String\>();
        queryParams.put('code','code');
        queryParams.put('state',authProviderConfiguration.get('State\_c'));
        Auth.AuthProviderCallbackState cbState =
            new Auth.AuthProviderCallbackState(null,null,queryParams);
        Auth.AuthProviderTokenResponse actualAuthProvResponse =
            concurCls.handleCallback(authProviderConfiguration, cbState);
        Auth.AuthProviderTokenResponse expectedAuthProvResponse =
            new Auth.AuthProviderTokenResponse(
                'Concur', OAUTH\_TOKEN, REFRESH\_TOKEN, null);

        Assert.areEqual(expectedAuthProvResponse.provider,
            actualAuthProvResponse.provider);
        Assert.areEqual(expectedAuthProvResponse.oauthToken,
            actualAuthProvResponse.oauthToken);
        Assert.areEqual(expectedAuthProvResponse.oauthSecretOrRefreshToken,
            actualAuthProvResponse.oauthSecretOrRefreshToken);
        Assert.areEqual(expectedAuthProvResponse.state,
            actualAuthProvResponse.state);
    }

    @IsTest
    static void testGetUserInfo() {
        Map<String,String\> authProviderConfiguration =
            setupAuthProviderConfig();
        Concur concurCls = new Concur();

        Test.setMock(HttpCalloutMock.class, new
            ConcurMockHttpResponseGenerator());

        Auth.AuthProviderTokenResponse response =
            new Auth.AuthProviderTokenResponse(
                PROVIDER, OAUTH\_TOKEN ,'sampleOauthSecret', STATE);
        Auth.UserData actualUserData = concurCls.getUserInfo(
            authProviderConfiguration, response) ;

        Map<String,String\> provMap = new Map<String,String\>();
        provMap.put('key1', 'value1');
        provMap.put('key2', 'value2');

        Auth.UserData expectedUserData = new Auth.UserData(LOGIN\_ID,
            FIRST\_NAME, LAST\_NAME, FULL\_NAME, EMAIL\_ADDRESS,
            null, LOCALE\_NAME, null, PROVIDER, null, provMap);

        Assert.isNotNull(expectedUserData);
        Assert.areEqual(expectedUserData.firstName,
            actualUserData.firstName);
        Assert.areEqual(expectedUserData.lastName,
            actualUserData.lastName);
        Assert.areEqual(expectedUserData.fullName,
            actualUserData.fullName);
        Assert.areEqual(expectedUserData.email,
            actualUserData.email);
        Assert.areEqual(expectedUserData.username,
            actualUserData.username);
        Assert.areEqual(expectedUserData.locale,
            actualUserData.locale);
        Assert.areEqual(expectedUserData.provider,
            actualUserData.provider);
        Assert.areEqual(expectedUserData.siteLoginUrl,
            actualUserData.siteLoginUrl);
    }

    // Implement a mock http response generator for Concur.
    public with sharing class ConcurMockHttpResponseGenerator implements HttpCalloutMock {
        public HTTPResponse respond(HTTPRequest req) {
            String namespace = API\_USER\_VERSION\_URL;
            String prefix = 'mockPrefix';

            Dom.Document doc = new Dom.Document();
            Dom.XmlNode xmlNode = doc.createRootElement(
                'mockRootNodeName', namespace, prefix);
            xmlNode.addChildElement('LoginId', namespace, prefix)
                .addTextNode(LOGIN\_ID);
            xmlNode.addChildElement('FirstName', namespace, prefix)
                .addTextNode(FIRST\_NAME);
            xmlNode.addChildElement('LastName', namespace, prefix)
                .addTextNode(LAST\_NAME);
            xmlNode.addChildElement('EmailAddress', namespace, prefix)
                .addTextNode(EMAIL\_ADDRESS);
            xmlNode.addChildElement('LocaleName', namespace, prefix)
                .addTextNode(LOCALE\_NAME);
            xmlNode.addChildElement('Token', null, null)
                .addTextNode(OAUTH\_TOKEN);
            System.debug(doc.toXmlString());
            // Create a fake response
            HttpResponse res = new HttpResponse();
            res.setHeader('Content-Type', 'application/xml');
            res.setBody(doc.toXmlString());
            res.setStatusCode(200);
            return res;
        }
    }
}