Table of Contents

Class TokenProvider

Namespace
Microsoft.ServiceBus
Assembly
Microsoft.ServiceBus.dll

Represents a security token provider with built-in factory methods returning some well-known token providers.

public abstract class TokenProvider
Inheritance
TokenProvider
Derived
Inherited Members

Constructors

TokenProvider(bool, bool)

Initializes a new instance of the TokenProvider class.

protected TokenProvider(bool cacheTokens, bool supportHttpAuthToken)

Parameters

cacheTokens bool

true if new security tokens are being cached; otherwise, false.

supportHttpAuthToken bool

true if web token is supported by this provider; otherwise, false.

TokenProvider(bool, bool, TokenScope)

Initializes a new instance of the TokenProvider class.

protected TokenProvider(bool cacheTokens, bool supportHttpAuthToken, TokenScope tokenScope)

Parameters

cacheTokens bool

true if new security tokens are being cached; otherwise, false.

supportHttpAuthToken bool

true if web token is supported by this provider; otherwise, false.

tokenScope TokenScope

The token scope associated with the provider.

TokenProvider(bool, bool, int, TokenScope)

Initializes a new instance of the TokenProvider class.

protected TokenProvider(bool cacheTokens, bool supportHttpAuthToken, int cacheSize, TokenScope tokenScope)

Parameters

cacheTokens bool

true if new security tokens are being cached; otherwise, false.

supportHttpAuthToken bool

true if web token is supported by this provider; otherwise, false.

cacheSize int

The size of the cache.

tokenScope TokenScope

The token scope associated with the provider.

Properties

CacheSize

Gets or sets the size of the cache.

public int CacheSize { get; set; }

Property Value

int

The size of the cache.

CacheTokens

Gets or sets a value that indicates whether new security tokens are being cached.

public bool CacheTokens { get; set; }

Property Value

bool

true if new security tokens are being cached; otherwise, false.

IsWebTokenSupported

Gets or sets a value that indicates whether web token is supported by this provider.

public bool IsWebTokenSupported { get; }

Property Value

bool

true if web token is supported by this provider; otherwise, false.

StripQueryParameters

Gets whether the token provider strips query parameters.

protected virtual bool StripQueryParameters { get; }

Property Value

bool

true if the token provider strips query parameters; otherwise, false.

TokenScope

Gets or sets the token scope associated with the provider.

public TokenScope TokenScope { get; }

Property Value

TokenScope

The token scope associated with the provider.

Methods

BeginGetToken(string, string, bool, TimeSpan, AsyncCallback, object)

Begins an asynchronous operation to get a security token.

public IAsyncResult BeginGetToken(string appliesTo, string action, bool bypassCache, TimeSpan timeout, AsyncCallback callback, object state)

Parameters

appliesTo string

The URI which the access token applies to.

action string

The request action.

bypassCache bool

true to ignore existing token information in the cache; false to use the token information in the cache.

timeout TimeSpan

The time span that specifies the timeout value for the message that gets the security token.

callback AsyncCallback

An AsyncCallback delegate that references the method to invoke when the operation is complete.

state object

A user-defined object that contains state information about the asynchronous operation.

Returns

IAsyncResult

An IAsyncResult object that references the asynchronous operation to get a token.

BeginGetWebToken(string, string, bool, TimeSpan, AsyncCallback, object)

Begins an asynchronous operation to get a web token.

public IAsyncResult BeginGetWebToken(string appliesTo, string action, bool bypassCache, TimeSpan timeout, AsyncCallback callback, object state)

Parameters

appliesTo string

The URI which the token applies to.

action string

The request action.

bypassCache bool

true to ignore existing token information in the cache; false to use the token information in the cache.

timeout TimeSpan

The time span that specifies the timeout value for the message that gets the security token.

callback AsyncCallback

An AsyncCallback delegate that references the method to invoke when the operation is complete.

state object

A user-defined object that contains state information about the asynchronous operation.

Returns

IAsyncResult

An IAsyncResult object that references the asynchronous operation to get a web token.

BuildKey(string, string)

Generates a key for the token provider.

protected virtual TokenProvider.Key BuildKey(string appliesTo, string action)

Parameters

appliesTo string

The URI which the access token applies to.

action string

The request action.

Returns

TokenProvider.Key

A generated key for the token provider.

Clear()

Clears the token provider.

public void Clear()

CreateOAuthTokenProvider(IEnumerable<Uri>, NetworkCredential)

Creates an OAuth (open standard for authorization) token provider.

public static TokenProvider CreateOAuthTokenProvider(IEnumerable<Uri> stsUris, NetworkCredential credential)

Parameters

stsUris IEnumerable<Uri>

The URIs of the Security Token Service (STS).

credential NetworkCredential

The user credential.

Returns

TokenProvider

The TokenProvider for returning OAuth token.

CreateSamlTokenProvider(string)

Creates a SAML token provider with the specified SAML token.

public static TokenProvider CreateSamlTokenProvider(string samlToken)

Parameters

samlToken string

The string that represents the SAML token.

Returns

TokenProvider

The TokenProvider for returning SAML token.

CreateSamlTokenProvider(string, TokenScope)

Creates a SAML token provider with the specified SAML token and scope.

public static TokenProvider CreateSamlTokenProvider(string samlToken, TokenScope tokenScope)

Parameters

samlToken string

The string that represents the SAML token.

tokenScope TokenScope

The token scope associated with the provider.

Returns

TokenProvider

The TokenProvider for returning SAML token.

CreateSamlTokenProvider(string, Uri)

Creates a SAML token provider with the specified SAML token and URI of the Security Token Service (STS).

public static TokenProvider CreateSamlTokenProvider(string samlToken, Uri stsUri)

Parameters

samlToken string

The string that represents the SAML token.

stsUri Uri

The URI of the Security Token Service (STS).

Returns

TokenProvider

The TokenProvider for returning SAML token.

CreateSamlTokenProvider(string, Uri, TokenScope)

Creates a SAML token provider with the specified SAML token, URI of the Security Token Service (STS) and token scope.

public static TokenProvider CreateSamlTokenProvider(string samlToken, Uri stsUri, TokenScope tokenScope)

Parameters

samlToken string

The string that represents the SAML token.

stsUri Uri

The URI of the Security Token Service (STS).

tokenScope TokenScope

The token scope associated with the provider.

Returns

TokenProvider

The TokenProvider for returning SAML token.

CreateSamlTokenProvider(string, Uri, int)

Creates a SAML token provider with the specified SAML token, URI of the Security Token Service (STS) and cache size.

public static TokenProvider CreateSamlTokenProvider(string samlToken, Uri stsUri, int cacheSize)

Parameters

samlToken string

The string that represents the SAML token.

stsUri Uri

The URI of the Security Token Service (STS).

cacheSize int

The size of the cache.

Returns

TokenProvider

The TokenProvider for returning SAML token.

CreateSamlTokenProvider(string, Uri, int, TokenScope)

Creates a SAML token provider with the specified SAML token, URI of the Security Token Service (STS), cache size and token scope.

public static TokenProvider CreateSamlTokenProvider(string samlToken, Uri stsUri, int cacheSize, TokenScope tokenScope)

Parameters

samlToken string

The string that represents the SAML token.

stsUri Uri

The URI of the Security Token Service (STS).

cacheSize int

The size of the cache.

tokenScope TokenScope

The token scope associated with the provider.

Returns

TokenProvider

The TokenProvider for returning SAML token.

CreateSharedAccessSignatureTokenProvider(string)

Creates a URL that grants access to the token provider with the specified shared access signature.

public static TokenProvider CreateSharedAccessSignatureTokenProvider(string sharedAccessSignature)

Parameters

sharedAccessSignature string

The shared access signature.

Returns

TokenProvider

Returns TokenProvider.

CreateSharedAccessSignatureTokenProvider(string, string)

Creates a URL that grants access to the token provider with the specified key name and shared access key.

public static TokenProvider CreateSharedAccessSignatureTokenProvider(string keyName, string sharedAccessKey)

Parameters

keyName string

The key name.

sharedAccessKey string

The shared access key.

Returns

TokenProvider

The created URL that grants access to token provider.

CreateSharedAccessSignatureTokenProvider(string, string, TokenScope)

Creates a URL that grants access to the token provider with the specified key name, shared access key and token scope.

public static TokenProvider CreateSharedAccessSignatureTokenProvider(string keyName, string sharedAccessKey, TokenScope tokenScope)

Parameters

keyName string

The key name.

sharedAccessKey string

The shared access key.

tokenScope TokenScope

The token scope associated with the provider.

Returns

TokenProvider

The created URL that grants access to token provider.

CreateSharedAccessSignatureTokenProvider(string, string, TimeSpan)

Creates a URL that grants access to the token provider with the specified key name, shared access key and token time to live.

public static TokenProvider CreateSharedAccessSignatureTokenProvider(string keyName, string sharedAccessKey, TimeSpan tokenTimeToLive)

Parameters

keyName string

The key name.

sharedAccessKey string

The shared access key.

tokenTimeToLive TimeSpan

The time for which the operation remains valid.

Returns

TokenProvider

The created URL that grants access to token provider.

CreateSharedAccessSignatureTokenProvider(string, string, TimeSpan, TokenScope)

Creates a URL that grants access to the token provider.

public static TokenProvider CreateSharedAccessSignatureTokenProvider(string keyName, string sharedAccessKey, TimeSpan tokenTimeToLive, TokenScope tokenScope)

Parameters

keyName string

The key name.

sharedAccessKey string

The shared access key.

tokenTimeToLive TimeSpan

The time for which the operation remains valid.

tokenScope TokenScope

The token scope associated with the provider.

Returns

TokenProvider

The created URL that grants access to token provider.

CreateSharedSecretTokenProvider(string, byte[])

Creates a shared secret token provider.

public static TokenProvider CreateSharedSecretTokenProvider(string issuerName, byte[] issuerSecret)

Parameters

issuerName string

The issuer name.

issuerSecret byte[]

The issuer secret.

Returns

TokenProvider

The TokenProvider for returning shared secret token.

CreateSharedSecretTokenProvider(string, byte[], TokenScope)

Creates a shared secret token provider.

public static TokenProvider CreateSharedSecretTokenProvider(string issuerName, byte[] issuerSecret, TokenScope tokenScope)

Parameters

issuerName string

The name of the issuer.

issuerSecret byte[]

The set of issuer secret.

tokenScope TokenScope

The token scope associated with the provider.

Returns

TokenProvider

The created token provider.

CreateSharedSecretTokenProvider(string, byte[], Uri)

Creates a shared secret token provider.

public static TokenProvider CreateSharedSecretTokenProvider(string issuerName, byte[] issuerSecret, Uri stsUri)

Parameters

issuerName string

The issuer name.

issuerSecret byte[]

The set of issuer secret.

stsUri Uri

The URI of the Security Token Service (STS).

Returns

TokenProvider

The TokenProvider for returning shared secret token.

CreateSharedSecretTokenProvider(string, byte[], Uri, TokenScope)

Creates a shared secret token provider.

public static TokenProvider CreateSharedSecretTokenProvider(string issuerName, byte[] issuerSecret, Uri stsUri, TokenScope tokenScope)

Parameters

issuerName string

The issuer name.

issuerSecret byte[]

The set of issuer secret.

stsUri Uri

The Security Token Service's endpoint Uri.

tokenScope TokenScope

The token scope associated with the provider.

Returns

TokenProvider

The created token provider.

CreateSharedSecretTokenProvider(string, string)

Creates a shared secret token provider.

public static TokenProvider CreateSharedSecretTokenProvider(string issuerName, string issuerSecret)

Parameters

issuerName string

The issuer name.

issuerSecret string

The issuer secret.

Returns

TokenProvider

The TokenProvider for returning shared secret token.

CreateSharedSecretTokenProvider(string, string, TokenScope)

Creates a shared secret token provider.

public static TokenProvider CreateSharedSecretTokenProvider(string issuerName, string issuerSecret, TokenScope tokenScope)

Parameters

issuerName string

The issuer name.

issuerSecret string

The issuer secret.

tokenScope TokenScope

The token scope associated with the provider.

Returns

TokenProvider

The created token provider.

CreateSharedSecretTokenProvider(string, string, Uri)

Creates a shared secret token provider.

public static TokenProvider CreateSharedSecretTokenProvider(string issuerName, string issuerSecret, Uri stsUri)

Parameters

issuerName string

The issuer name.

issuerSecret string

The issuer secret.

stsUri Uri

The URI of the Security Token Service (STS).

Returns

TokenProvider

The TokenProvider for returning shared secret token.

CreateSharedSecretTokenProvider(string, string, Uri, TokenScope)

Creates a shared secret token provider.

public static TokenProvider CreateSharedSecretTokenProvider(string issuerName, string issuerSecret, Uri stsUri, TokenScope tokenScope)

Parameters

issuerName string

The issuer name.

issuerSecret string

The issuer secret.

stsUri Uri

The URI of the Security Token Service (STS).

tokenScope TokenScope

The token scope associated with the provider.

Returns

TokenProvider

The created token provider.

CreateSimpleWebTokenProvider(string)

Creates a simple web token provider.

public static TokenProvider CreateSimpleWebTokenProvider(string token)

Parameters

token string

The string that represents the simple web token.

Returns

TokenProvider

The TokenProvider for returning simple web token.

CreateSimpleWebTokenProvider(string, TokenScope)

Creates a simple web token provider.

public static TokenProvider CreateSimpleWebTokenProvider(string token, TokenScope tokenScope)

Parameters

token string

The string that represents the simple web token.

tokenScope TokenScope

The token scope associated with the provider.

Returns

TokenProvider

The created simple web token provider.

CreateSimpleWebTokenProvider(string, Uri)

Creates a simple web token provider.

public static TokenProvider CreateSimpleWebTokenProvider(string token, Uri stsUri)

Parameters

token string

The string that represents the simple web token.

stsUri Uri

The URI of the Security Token Service (STS).

Returns

TokenProvider

The TokenProvider for returning simple web token.

CreateSimpleWebTokenProvider(string, Uri, TokenScope)

Creates a simple web token provider.

public static TokenProvider CreateSimpleWebTokenProvider(string token, Uri stsUri, TokenScope tokenScope)

Parameters

token string

The string that represents the simple web token.

stsUri Uri

The URI of the Security Token Service (STS).

tokenScope TokenScope

The token scope associated with the provider.

Returns

TokenProvider

The created simple web token provider.

CreateWindowsTokenProvider(IEnumerable<Uri>)

Creates a windows token provider.

public static TokenProvider CreateWindowsTokenProvider(IEnumerable<Uri> stsUris)

Parameters

stsUris IEnumerable<Uri>

The URIs of the Security Token Service (STS).

Returns

TokenProvider

The TokenProvider for returning the windows token.

CreateWindowsTokenProvider(IEnumerable<Uri>, NetworkCredential)

Creates a windows token provider.

public static TokenProvider CreateWindowsTokenProvider(IEnumerable<Uri> stsUris, NetworkCredential credential)

Parameters

stsUris IEnumerable<Uri>

The URIs of the Security Token Service (STS).

credential NetworkCredential

The user credential.

Returns

TokenProvider

The TokenProvider for returning the windows token.

EndGetToken(IAsyncResult)

Completes an asynchronous operation to get a security token.

public SecurityToken EndGetToken(IAsyncResult result)

Parameters

result IAsyncResult

An IAsyncResult object that references the asynchronous operation to get a token.

Returns

SecurityToken

The System.IdentityModel.Tokens.SecurityToken object.

EndGetWebToken(IAsyncResult)

Completes an asynchronous operation to get a web token.

public string EndGetWebToken(IAsyncResult result)

Parameters

result IAsyncResult

An IAsyncResult object that references the asynchronous operation to get a web token.

Returns

string

The string that represents the web token.

GetTokenAsync(string, string, bool, TimeSpan)

Asynchronously retrieves the token for the provider.

public Task<SecurityToken> GetTokenAsync(string appliesTo, string action, bool bypassCache, TimeSpan timeout)

Parameters

appliesTo string

The URI which the access token applies to.

action string

The request action.

bypassCache bool

true to ignore existing token information in the cache; false to use the token information in the cache.

timeout TimeSpan

The time span that specifies the timeout value for the message that gets the security token.

Returns

Task<SecurityToken>

The result of the asynchronous operation.

GetWebTokenAsync(string, string, bool, TimeSpan)

Asynchronously retrieves the web token for the provider.

public Task<string> GetWebTokenAsync(string appliesTo, string action, bool bypassCache, TimeSpan timeout)

Parameters

appliesTo string

The URI which the access token applies to.

action string

The request action.

bypassCache bool

true to ignore existing token information in the cache; false to use the token information in the cache.

timeout TimeSpan

The time span that specifies the timeout value for the message that gets the security token.

Returns

Task<string>

The result of the asynchronous operation.

NormalizeAppliesTo(string)

Returns an object whose value is the same as the token provider.

protected virtual string NormalizeAppliesTo(string appliesTo)

Parameters

appliesTo string

The URI which the access token applies to.

Returns

string

The returned object.

OnBeginGetToken(string, string, TimeSpan, AsyncCallback, object)

Executes upon calling the BeginGetToken method.

protected abstract IAsyncResult OnBeginGetToken(string appliesTo, string action, TimeSpan timeout, AsyncCallback callback, object state)

Parameters

appliesTo string

The URI which the access token applies to.

action string

The request action.

timeout TimeSpan

The time span that specifies the timeout value for the message that gets the security token.

callback AsyncCallback

An AsyncCallback delegate that references the method to invoke when the operation is complete.

state object

A user-defined object that contains state information about the asynchronous operation.

Returns

IAsyncResult

An IAsyncResult object that references the asynchronous operation to get a token.

OnBeginGetWebToken(string, string, TimeSpan, AsyncCallback, object)

Executes upon calling the BeginGetWebToken method.

protected abstract IAsyncResult OnBeginGetWebToken(string appliesTo, string action, TimeSpan timeout, AsyncCallback callback, object state)

Parameters

appliesTo string

The URI which the access token applies to.

action string

The request action.

timeout TimeSpan

The time span that specifies the timeout value for the message that gets the security token.

callback AsyncCallback

An AsyncCallback delegate that references the method to invoke when the operation is complete.

state object

A user-defined object that contains state information about the asynchronous operation.

Returns

IAsyncResult

An IAsyncResult object that references the asynchronous operation to get a web token.

OnEndGetToken(IAsyncResult, out DateTime)

Executes upon calling the EndGetToken method.

protected abstract SecurityToken OnEndGetToken(IAsyncResult result, out DateTime cacheUntil)

Parameters

result IAsyncResult

An IAsyncResult object that references the asynchronous operation to get a token.

cacheUntil DateTime

When this method returns, contains the expiration date and time of the token information in the cache.

Returns

SecurityToken

The System.IdentityModel.Tokens.SecurityToken object.

OnEndGetWebToken(IAsyncResult, out DateTime)

Executes upon calling the EndGetWebToken method.

protected abstract string OnEndGetWebToken(IAsyncResult result, out DateTime cacheUntil)

Parameters

result IAsyncResult

An IAsyncResult object that references the asynchronous operation to get a web token.

cacheUntil DateTime

When this method returns, contains the expiration date and time of the token information in the cache.

Returns

string

The string that represents the web token.