# Class: MPCCredentialProvider

## Constructor

#### new MPCCredentialProvider(token, bearer, expiresIn)

  Class used to provide credentials for ECloud Token Based Authentication.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `token` | string |  |
  `bearer` | string | <optional> |
  `expiresIn` | Number |  |

## Members

#### expiresIn

  Session token expiration time in seconds

#### token :string

  Token to be used used for authentication.

  ##### Type:

  - string
  Inherited From:
    - AvayaClientServices.Config.CredentialTokenProvider#token

## Methods

#### onAuthenticationChallenge(challenge, callback) → {void}

  Function called after credentials were required.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `challenge` | Object | It is not used right now.
  `callback` | function | Function to be called after credentials are retrieved.

  Inherited From:
    - AvayaClientServices.Config.AbstractCredentialProvider#onAuthenticationChallenge

  ##### Returns:

  { void }

#### setToken(sessionToken)

  Updates session token

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `sessionToken` | String |

### Callbacks

#### addOnTokenRefreshedCallback(callback) → {void}

  Adds new onTokenRefreshedCallback

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `callback` | AvayaClientServices.Config.MPCCredentialProvider#onTokenRefreshedCallback |

  ##### Returns:

  { void }

#### removeOnInvalidCredentialsCallback(callback) → {void}

  Removes callback from invalidCredentialsProvided.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `callback` | AvayaClientServices.Config.AbstractCredentialProvider#onInvalidCredentialsProvided |

  Inherited From:
    - AvayaClientServices.Config.AbstractCredentialProvider#removeOnInvalidCredentialsCallback

  ##### Returns:

  { void }

#### removeOnTokenRefreshedCallback(callback) → {void}

  Removes existing onTokenRefreshedCallback

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `callback` | AvayaClientServices.Config.MPCCredentialProvider#onTokenRefreshedCallback |

  ##### Returns:

  { void }

## Type Definitions

#### onInvalidCredentialsProvided() → {void}

  Interface for callback function to be invoked when provided credentials are invalid.

  ##### Example

  Using callback to refresh session token using existing credentials provider:

      credentialProvider.addOnInvalidCredentialsCallback(function (invalidCredentialsEvent) {
          // Consumer application goes and retrieves new session token

          // Updates session token and retry
          credentialProvider.setToken(newSessionToken);
          invalidCredentialsEvent.retry(credentialProvider);
      });

  ##### See:

    - AvayaClientServices.Config.CredentialTokenProvider#onInvalidCredentialsProvided

  ##### Returns:

  { void }

#### onTokenRefreshedCallback(credentialProvider) → {void}

  Interface for callback function to be invoked when token is refreshed.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `credentialProvider` | AvayaClientServices.Config.MPCCredentialProvider | Token credential provider.

  ##### Returns:

  { void }