Beispiel #1
0
 /// <summary>
 /// Sets up an instance of <typeparamref name="T"/> for an OAuth provider.
 /// </summary>
 /// <typeparam name="T">The type of the OAuth options to set up.</typeparam>
 /// <param name="auth">The OAuth options to set up.</param>
 /// <param name="options">The <see cref="ExternalSignInOptions"/> to use to set up the instance.</param>
 /// <param name="loggerFactory">The <see cref="ILoggerFactory"/> to use.</param>
 private static void SetupOAuth <T>(T auth, ExternalSignInOptions options, ILoggerFactory loggerFactory)
     where T : OAuthOptions
 {
     auth.ClientId     = options.ClientId;
     auth.ClientSecret = options.ClientSecret;
     auth.Events       = new OAuthEventsHandler(auth, loggerFactory);
 }
Beispiel #2
0
        /// <summary>
        /// Configures an instance of <typeparamref name="T"/> for an OAuth provider.
        /// </summary>
        /// <typeparam name="T">The type of the OAuth options to configure.</typeparam>
        /// <param name="name">The name of the OAuth provider to configure.</param>
        /// <param name="auth">The OAuth options to configure.</param>
        /// <param name="options">The <see cref="ExternalSignInOptions"/> to use to configure the instance.</param>
        private void ConfigureOAuth <T>(string name, T auth, ExternalSignInOptions options)
            where T : OAuthOptions
        {
            auth.ClientId     = options.ClientId;
            auth.ClientSecret = options.ClientSecret;
            auth.Events       = new OAuthEventsHandler(auth, AuthEvents, LoggerFactory);

            ConfigureRemoteAuth(name, auth);
        }
        /// <summary>
        /// Tries to get the external sign-in settings for the specified provider.
        /// </summary>
        /// <param name="name">The name of the provider to get the provider settings for.</param>
        /// <param name="options">When the method returns, containsint the provider options, if enabled.</param>
        /// <returns>
        /// <see langword="true"/> if the specified provider is enabled; otherwise <see langword="false"/>.
        /// </returns>
        private bool TryGetProvider(string name, out ExternalSignInOptions options)
        {
            options = null;
            ExternalSignInOptions signInOptions = null;

            bool isEnabled =
                _options?.Authentication?.ExternalProviders?.TryGetValue(name, out signInOptions) == true &&
                signInOptions?.IsEnabled == true &&
                !string.IsNullOrEmpty(signInOptions?.ClientId) &&
                !string.IsNullOrEmpty(signInOptions?.ClientSecret);

            if (isEnabled)
            {
                options = signInOptions;
            }

            return(isEnabled);
        }