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
booltrue if new security tokens are being cached; otherwise, false.
supportHttpAuthToken
booltrue 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
booltrue if new security tokens are being cached; otherwise, false.
supportHttpAuthToken
booltrue if web token is supported by this provider; otherwise, false.
tokenScope
TokenScopeThe 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
booltrue if new security tokens are being cached; otherwise, false.
supportHttpAuthToken
booltrue if web token is supported by this provider; otherwise, false.
cacheSize
intThe size of the cache.
tokenScope
TokenScopeThe 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
stringThe URI which the access token applies to.
action
stringThe request action.
bypassCache
booltrue to ignore existing token information in the cache; false to use the token information in the cache.
timeout
TimeSpanThe time span that specifies the timeout value for the message that gets the security token.
callback
AsyncCallbackAn AsyncCallback delegate that references the method to invoke when the operation is complete.
state
objectA 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
stringThe URI which the token applies to.
action
stringThe request action.
bypassCache
booltrue to ignore existing token information in the cache; false to use the token information in the cache.
timeout
TimeSpanThe time span that specifies the timeout value for the message that gets the security token.
callback
AsyncCallbackAn AsyncCallback delegate that references the method to invoke when the operation is complete.
state
objectA 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
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
NetworkCredentialThe 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
stringThe 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
stringThe string that represents the SAML token.
tokenScope
TokenScopeThe 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
stringThe string that represents the SAML token.
stsUri
UriThe 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
stringThe string that represents the SAML token.
stsUri
UriThe URI of the Security Token Service (STS).
tokenScope
TokenScopeThe 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
stringThe string that represents the SAML token.
stsUri
UriThe URI of the Security Token Service (STS).
cacheSize
intThe 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
stringThe string that represents the SAML token.
stsUri
UriThe URI of the Security Token Service (STS).
cacheSize
intThe size of the cache.
tokenScope
TokenScopeThe 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
stringThe 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
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
stringThe key name.
sharedAccessKey
stringThe shared access key.
tokenScope
TokenScopeThe 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
stringThe key name.
sharedAccessKey
stringThe shared access key.
tokenTimeToLive
TimeSpanThe 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
stringThe key name.
sharedAccessKey
stringThe shared access key.
tokenTimeToLive
TimeSpanThe time for which the operation remains valid.
tokenScope
TokenScopeThe 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
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
stringThe name of the issuer.
issuerSecret
byte[]The set of issuer secret.
tokenScope
TokenScopeThe 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
stringThe issuer name.
issuerSecret
byte[]The set of issuer secret.
stsUri
UriThe 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
stringThe issuer name.
issuerSecret
byte[]The set of issuer secret.
stsUri
UriThe Security Token Service's endpoint Uri.
tokenScope
TokenScopeThe 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
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
stringThe issuer name.
issuerSecret
stringThe issuer secret.
tokenScope
TokenScopeThe 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
stringThe issuer name.
issuerSecret
stringThe issuer secret.
stsUri
UriThe 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
stringThe issuer name.
issuerSecret
stringThe issuer secret.
stsUri
UriThe URI of the Security Token Service (STS).
tokenScope
TokenScopeThe 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
stringThe 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
stringThe string that represents the simple web token.
tokenScope
TokenScopeThe 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
stringThe string that represents the simple web token.
stsUri
UriThe 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
stringThe string that represents the simple web token.
stsUri
UriThe URI of the Security Token Service (STS).
tokenScope
TokenScopeThe 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
NetworkCredentialThe 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
IAsyncResultAn 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
IAsyncResultAn IAsyncResult object that references the asynchronous operation to get a web token.
Returns
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
stringThe URI which the access token applies to.
action
stringThe request action.
bypassCache
booltrue to ignore existing token information in the cache; false to use the token information in the cache.
timeout
TimeSpanThe 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
stringThe URI which the access token applies to.
action
stringThe request action.
bypassCache
booltrue to ignore existing token information in the cache; false to use the token information in the cache.
timeout
TimeSpanThe time span that specifies the timeout value for the message that gets the security token.
Returns
NormalizeAppliesTo(string)
Returns an object whose value is the same as the token provider.
protected virtual string NormalizeAppliesTo(string appliesTo)
Parameters
appliesTo
stringThe 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
stringThe URI which the access token applies to.
action
stringThe request action.
timeout
TimeSpanThe time span that specifies the timeout value for the message that gets the security token.
callback
AsyncCallbackAn AsyncCallback delegate that references the method to invoke when the operation is complete.
state
objectA 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
stringThe URI which the access token applies to.
action
stringThe request action.
timeout
TimeSpanThe time span that specifies the timeout value for the message that gets the security token.
callback
AsyncCallbackAn AsyncCallback delegate that references the method to invoke when the operation is complete.
state
objectA 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
IAsyncResultAn IAsyncResult object that references the asynchronous operation to get a token.
cacheUntil
DateTimeWhen 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
IAsyncResultAn IAsyncResult object that references the asynchronous operation to get a web token.
cacheUntil
DateTimeWhen this method returns, contains the expiration date and time of the token information in the cache.