Authenticating a User Using a Token

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.

An example of when you might want to use a temporary token for authentication is when you want to improve the performance of your application by passing the token instead of frequently authenticating during a single user session.

Typical Goals

In this scenario, the goal is to use the token as an alternative to using credentials.

Solution

Call the GetIdentity method on the security cache object, specifying the token that was created when the identity was originally cached.

QuickStart

For an extended example of how to use the GetIdentity method to retrieve a user identity, see Walkthrough: Authenticate a User Using a Token.

Using GetIdentity

The following code shows how to use the GetIdentity method.

ISecurityCacheProvider cache = SecurityCacheFactory.GetSecurityCacheProvider("Caching Store Provider");

// Cache the identity. 
IToken token = cache.SaveIdentity(new GenericIdentity("Username"));

// Retrieves the identity previously saved by using the corresponding token.
IIdentity savedIdentity = cache.GetIdentity(token);
'Usage
Dim cache As ISecurityCacheProvider = SecurityCacheFactory.GetSecurityCacheProvider("Caching Store Provider")

' Cache the identity. The SecurityCache will generate a token which is then
' returned to us.
Dim token As IToken = cache.SaveIdentity(New GenericIdentity("Username"))

' Retrieves the identity previously saved by using the corresponding token.
Dim savedIdentity As IIdentity = cache.GetIdentity(token)

Usage Notes

Alternately, you can use the GetPrincipal or GetProfile methods to retrieve a user principal or a user profile.

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.