TokenCachePersistenceOptions クラス

定義

トークン キャッシュのストレージを制御するオプション。

public class TokenCachePersistenceOptions
type TokenCachePersistenceOptions = class
Public Class TokenCachePersistenceOptions
継承
TokenCachePersistenceOptions
派生

これは、TokenCachePersistenceOptions と AuthenticationRecord を組み合わせて使用して、クライアント アプリケーションの実行全体でサイレント認証を有効にする方法を示す例です。

const string TOKEN_CACHE_NAME = "MyTokenCache";
InteractiveBrowserCredential credential;
AuthenticationRecord authRecord;

// Check if an AuthenticationRecord exists on disk.
// If it does not exist, get one and serialize it to disk.
// If it does exist, load it from disk and deserialize it.
if (!File.Exists(AUTH_RECORD_PATH))
{
    // Construct a credential with TokenCachePersistenceOptions specified to ensure that the token cache is persisted to disk.
    // We can also optionally specify a name for the cache to avoid having it cleared by other applications.
    credential = new InteractiveBrowserCredential(
        new InteractiveBrowserCredentialOptions { TokenCachePersistenceOptions = new TokenCachePersistenceOptions { Name = TOKEN_CACHE_NAME } });

    // Call AuthenticateAsync to fetch a new AuthenticationRecord.
    authRecord = await credential.AuthenticateAsync();

    // Serialize the AuthenticationRecord to disk so that it can be re-used across executions of this initialization code.
    using var authRecordStream = new FileStream(AUTH_RECORD_PATH, FileMode.Create, FileAccess.Write);
    await authRecord.SerializeAsync(authRecordStream);
}
else
{
    // Load the previously serialized AuthenticationRecord from disk and deserialize it.
    using var authRecordStream = new FileStream(AUTH_RECORD_PATH, FileMode.Open, FileAccess.Read);
    authRecord = await AuthenticationRecord.DeserializeAsync(authRecordStream);

    // Construct a new client with our TokenCachePersistenceOptions with the addition of the AuthenticationRecord property.
    // This tells the credential to use the same token cache in addition to which account to try and fetch from cache when GetToken is called.
    credential = new InteractiveBrowserCredential(
        new InteractiveBrowserCredentialOptions
        {
            TokenCachePersistenceOptions = new TokenCachePersistenceOptions { Name = TOKEN_CACHE_NAME },
            AuthenticationRecord = authRecord
        });
}

// Construct our client with the credential which is connected to the token cache
// with the capability of silent authentication for the account specified in the AuthenticationRecord.
var client = new SecretClient(new Uri("https://myvault.vault.azure.net/"), credential);

コンストラクター

TokenCachePersistenceOptions()

トークン キャッシュのストレージを制御するオプション。

プロパティ

Name

を一意に識別する TokenCachePersistenceOptions名前。

UnsafeAllowUnencryptedStorage

true に設定すると、OS レベルのユーザー暗号化が使用できない場合、トークン キャッシュは暗号化されていないファイルとして保持される可能性があります。 false に設定すると、OS レベルのユーザー暗号化が使用できない場合、トークン キャッシュによって がスロー CredentialUnavailableException されます。

適用対象