Export (0) Print
Expand All

Obtaining a Temporary Token for an Authenticated User

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 obtain a temporary token for an authenticated user is when you want to improve the performance of your application by passing the token instead of frequently authenticating the same token during a single user session. You can also use the approach described here to save a user principal or a user identity.

Typical Goals

In this scenario, the goal is to pass the identity of an authenticated user for the user to a cache and retrieve a token corresponding to the identity.

Solution

Declare member variables to hold a token and a cache. Authenticate the user and initialize the security cache by calling GetSecurityCacheProvider on the SecurityCacheFactory. Call the SaveIdentity method on the CachingStoreProvider. This stores the identity information and returns a token.

QuickStart

For an extended example of how to use the SaveIdentity method to obtain a token for an authenticated user, see Walkthrough: Obtain a Temporary Token for an Authenticated User.

Using SaveIdentity

The following code shows how to use the SaveIdentity method.

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

// Cache the identity. The SecurityCache will generate a token that is then
// returned to us.
IToken token = cache.SaveIdentity(new GenericIdentity("Username"));

Usage Notes

Alternatively, you can use the SavePrincipal or SaveProfile methods to retrieve a token for a principal or a profile. Each of these objects can be grouped together with the same 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.
Show:
© 2014 Microsoft