C# Class IBM.Watson.DeveloperCloud.Utilities.Credentials

Helper class for holding a user and password or authorization token, used by both the WSCOnnector and RESTConnector.
Afficher le fichier Open project: ZeeNastalski/unity-watson-chat

Méthodes publiques

Méthode Description
CreateAuthorization ( ) : string

Create basic authentication header data for REST requests.

Credentials ( TokenOptions iamTokenOptions, string serviceUrl = null ) : FullSerializer

Constructor that takes IAM token options.

Credentials ( string url = null ) : FullSerializer

Constructor that takes the URL. Used for token authentication.

Credentials ( string apiKey, string url = null ) : FullSerializer

Constructor that takes an authentication token created by the user or an ApiKey. If no URL is set then default to the non-IAM Visual Recognition endpoint.

Credentials ( string username, string password, string url = null ) : FullSerializer

Constructor that takes the user name and password.

GetToken ( ) : void

This function sends an access token back through a callback. The source of the token is determined by the following logic: 1. If user provides their own managed access token, assume it is valid and send it 2. If this class is managing tokens and does not yet have one, make a request for one 3. If this class is managing tokens and the token has expired, refresh it 4. If this class is managing tokens and has a valid token stored, send it

HasApiKey ( ) : bool

Do we have an ApiKey?

HasCredentials ( ) : bool

Do we have credentials?

HasIamApikey ( ) : bool

Do we have an IAM apikey?

HasIamAuthorizationToken ( ) : bool

Do we have an IAM authentication token?

HasIamTokenData ( ) : bool

Do we have IamTokenData?

HasWatsonAuthenticationToken ( ) : bool

Do we have an authentication token?

IsRefreshTokenExpired ( ) : bool

Used as a fail-safe to prevent the condition of a refresh token expiring, which could happen after around 30 days.This function will return true if it has been at least 7 days and 1 hour since the last token was retrieved.

IsTokenExpired ( ) : bool

Check if currently stored token is expired. Using a buffer to prevent the edge case of the token expiring before the request could be made. The buffer will be a fraction of the total TTL. Using 80%.

RefreshIamToken ( SuccessCallback successCallback, FailCallback failCallback, Dictionary customData = null ) : bool

Refresh an IAM token using a refresh token.

RequestIamToken ( SuccessCallback successCallback, FailCallback failCallback, Dictionary customData = null ) : bool

Request an IAM token using an API key.

SaveTokenInfo ( IamTokenData iamTokenData ) : void

Save the response from the IAM service request to the object's state.

SetAccessToken ( string iamAccessToken ) : void

Set a self-managed IAM access token. The access token should be valid and not yet expired. By using this method, you accept responsibility for managing the access token yourself.You must set a new access token before this one expires. Failing to do so will result in authentication errors after this token expires.

Private Methods

Méthode Description
OnGetToken ( IamTokenData iamTokenData, Dictionary customData ) : void
OnGetTokenFail ( RESTConnector.Error error, Dictionary customData ) : void
OnRefreshIamTokenResponse ( RESTConnector.Request req, RESTConnector.Response resp ) : void
OnRequestIamTokenResponse ( RESTConnector.Request req, RESTConnector.Response resp ) : void
SetCredentials ( TokenOptions iamTokenOptions, string serviceUrl = null ) : void
SetCredentials ( string username, string password, string url = null ) : void

Method Details

CreateAuthorization() public méthode

Create basic authentication header data for REST requests.
public CreateAuthorization ( ) : string
Résultat string

Credentials() public méthode

Constructor that takes IAM token options.
public Credentials ( TokenOptions iamTokenOptions, string serviceUrl = null ) : FullSerializer
iamTokenOptions TokenOptions
serviceUrl string
Résultat FullSerializer

Credentials() public méthode

Constructor that takes the URL. Used for token authentication.
public Credentials ( string url = null ) : FullSerializer
url string
Résultat FullSerializer

Credentials() public méthode

Constructor that takes an authentication token created by the user or an ApiKey. If no URL is set then default to the non-IAM Visual Recognition endpoint.
public Credentials ( string apiKey, string url = null ) : FullSerializer
apiKey string
url string The service endpoint.
Résultat FullSerializer

Credentials() public méthode

Constructor that takes the user name and password.
public Credentials ( string username, string password, string url = null ) : FullSerializer
username string The string containing the user name.
password string A string containing the password.
url string The service endpoint.
Résultat FullSerializer

GetToken() public méthode

This function sends an access token back through a callback. The source of the token is determined by the following logic: 1. If user provides their own managed access token, assume it is valid and send it 2. If this class is managing tokens and does not yet have one, make a request for one 3. If this class is managing tokens and the token has expired, refresh it 4. If this class is managing tokens and has a valid token stored, send it
public GetToken ( ) : void
Résultat void

HasApiKey() public méthode

Do we have an ApiKey?
public HasApiKey ( ) : bool
Résultat bool

HasCredentials() public méthode

Do we have credentials?
public HasCredentials ( ) : bool
Résultat bool

HasIamApikey() public méthode

Do we have an IAM apikey?
public HasIamApikey ( ) : bool
Résultat bool

HasIamAuthorizationToken() public méthode

Do we have an IAM authentication token?
public HasIamAuthorizationToken ( ) : bool
Résultat bool

HasIamTokenData() public méthode

Do we have IamTokenData?
public HasIamTokenData ( ) : bool
Résultat bool

HasWatsonAuthenticationToken() public méthode

Do we have an authentication token?
public HasWatsonAuthenticationToken ( ) : bool
Résultat bool

IsRefreshTokenExpired() public méthode

Used as a fail-safe to prevent the condition of a refresh token expiring, which could happen after around 30 days.This function will return true if it has been at least 7 days and 1 hour since the last token was retrieved.
public IsRefreshTokenExpired ( ) : bool
Résultat bool

IsTokenExpired() public méthode

Check if currently stored token is expired. Using a buffer to prevent the edge case of the token expiring before the request could be made. The buffer will be a fraction of the total TTL. Using 80%.
public IsTokenExpired ( ) : bool
Résultat bool

RefreshIamToken() public méthode

Refresh an IAM token using a refresh token.
public RefreshIamToken ( SuccessCallback successCallback, FailCallback failCallback, Dictionary customData = null ) : bool
successCallback SuccessCallback The success callback.
failCallback FailCallback The fail callback.
customData Dictionary Dictionary of custom data.
Résultat bool

RequestIamToken() public méthode

Request an IAM token using an API key.
public RequestIamToken ( SuccessCallback successCallback, FailCallback failCallback, Dictionary customData = null ) : bool
successCallback SuccessCallback The request callback.
failCallback FailCallback The fail callback.
customData Dictionary Dictionary of custom data.
Résultat bool

SaveTokenInfo() public méthode

Save the response from the IAM service request to the object's state.
public SaveTokenInfo ( IamTokenData iamTokenData ) : void
iamTokenData IamTokenData Response object from IAM service request
Résultat void

SetAccessToken() public méthode

Set a self-managed IAM access token. The access token should be valid and not yet expired. By using this method, you accept responsibility for managing the access token yourself.You must set a new access token before this one expires. Failing to do so will result in authentication errors after this token expires.
public SetAccessToken ( string iamAccessToken ) : void
iamAccessToken string A valid, non-expired IAM access token.
Résultat void