/// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="options">The options to be passed down to the underlying Authentication library handling the authentication operations.</param>
 /// <param name="tokenCache">The token cache to use to store tokens.</param>
 /// <param name="protectedStorage">The protect storage where refresh tokens will be stored.</param>
 /// <param name="accountClaimsPrincipalFactory">The <see cref="AccountClaimsPrincipalFactory{TAccount}"/> used to generate the <see cref="ClaimsPrincipal"/> for the user.</param>
 public TizenAuthenticationService(
     IOptionsSnapshot <RemoteAuthenticationOptions <TProviderOptions> > options,
     ITokenCache tokenCache,
     IProtectedStorage protectedStorage,
     AccountClaimsPrincipalFactory <TAccount> accountClaimsPrincipalFactory) : base(options, tokenCache, protectedStorage, accountClaimsPrincipalFactory)
 {
 }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MsalAuthenticationService{TAccount, TProviderOptions}"/> class.
        /// </summary>
        /// <param name="clientApplication">The public client application to use to connect.</param>
        /// <param name="protectedStorage">The protect storage where refresh tokens will be stored.</param>
        /// <param name="accountClaimsPrincipalFactory">The <see cref="AccountClaimsPrincipalFactory{TAccount}"/> used to generate the <see cref="ClaimsPrincipal"/> for the user.</param>
        public MsalAuthenticationService(
            PublicClientApplication clientApplication,
            IProtectedStorage protectedStorage,
            AccountClaimsPrincipalFactory <TAccount> accountClaimsPrincipalFactory) :
            base(new RemoteAuthenticationOptions <TProviderOptions>()
        {
            ProviderOptions = new TProviderOptions()
            {
#pragma warning disable CA1062 // Validate arguments of public methods
                ClientCapabilities = clientApplication.AppConfig.ClientCapabilities,
                ClientId           = clientApplication.AppConfig.ClientId,
                ClientName         = clientApplication.AppConfig.ClientName,
                ClientVersion      = clientApplication.AppConfig.ClientVersion,
                EnablePiiLogging   = clientApplication.AppConfig.EnablePiiLogging,
                IsDefaultPlatformLoggingEnabled = clientApplication.AppConfig.IsDefaultPlatformLoggingEnabled,
                LogLevel    = clientApplication.AppConfig.LogLevel,
                RedirectUri = clientApplication.AppConfig.RedirectUri,
                TenantId    = clientApplication.AppConfig.TenantId,
#pragma warning restore CA1062 // Validate arguments of public methods
            },
        }, accountClaimsPrincipalFactory)
        {
            _clientApplication = clientApplication ?? throw new ArgumentNullException(nameof(clientApplication));

            MsalDefaultOptionsConfiguration.Configure(Options as RemoteAuthenticationOptions <PublicClientApplicationOptions>);

            SetUpSerializationHandlers(protectedStorage);
        }
示例#3
0
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="options">The options to be passed down to the underlying Authentication library handling the authentication operations.</param>
 /// <param name="tokenCache">The token cache to use to store tokens.</param>
 /// <param name="protectedStorage">The protect storage where refresh tokens will be stored.</param>
 /// <param name="accountClaimsPrincipalFactory">The <see cref="AccountClaimsPrincipalFactory{TAccount}"/> used to generate the <see cref="ClaimsPrincipal"/> for the user.</param>
 protected OidcAuthenticationService(
     IOptionsSnapshot <RemoteAuthenticationOptions <TProviderOptions> > options,
     ITokenCache tokenCache,
     IProtectedStorage protectedStorage,
     AccountClaimsPrincipalFactory <TAccount> accountClaimsPrincipalFactory) : base(options?.Value, accountClaimsPrincipalFactory)
 {
     TokenCache        = tokenCache ?? throw new ArgumentNullException(nameof(tokenCache));
     _protectedStorage = protectedStorage;
 }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MsalAuthenticationService{TAccount, TProviderOptions}"/> class.
        /// </summary>
        /// <param name="options">The options to be passed down to the underlying Authentication library handling the authentication operations.</param>
        /// <param name="protectedStorage">The protect storage where refresh tokens will be stored.</param>
        /// <param name="accountClaimsPrincipalFactory">The <see cref="AccountClaimsPrincipalFactory{TAccount}"/> used to generate the <see cref="ClaimsPrincipal"/> for the user.</param>
        public MsalAuthenticationService(
            IOptionsSnapshot <RemoteAuthenticationOptions <TProviderOptions> > options,
            IProtectedStorage protectedStorage,
            AccountClaimsPrincipalFactory <TAccount> accountClaimsPrincipalFactory) :
            base(options?.Value, accountClaimsPrincipalFactory)
        {
            _clientApplication = (PublicClientApplication)PublicClientApplicationBuilder.CreateWithApplicationOptions(Options.ProviderOptions).Build();

            SetUpSerializationHandlers(protectedStorage);
        }
示例#5
0
        private void SetUpSerializationHandlers(IProtectedStorage protectedStorage)
        {
            // these platforms have their own secure storage.
            if (DeviceInfo.Platform == DevicePlatform.Android ||
                DeviceInfo.Platform == DevicePlatform.iOS)
            {
                return;
            }

            // set up serialization handlers.
            _clientApplication.UserTokenCache.SetBeforeAccessAsync(async args =>
            {
                if (args.HasStateChanged)
                {
                    return;
                }

                var bytes = await protectedStorage.GetAsync <byte[]>(TokenCacheKey).ConfigureAwait(false);
                if (bytes is null)
                {
                    return;
                }

                args.TokenCache.DeserializeMsalV3(bytes);
            });

            _clientApplication.UserTokenCache.SetAfterAccessAsync(async args =>
            {
                if (!args.HasStateChanged)
                {
                    return;
                }

                var bytes = args.TokenCache.SerializeMsalV3();
                await protectedStorage.SetAsync(TokenCacheKey, bytes).ConfigureAwait(false);
            });
        }