コード例 #1
0
        /// <summary>
        /// Configure
        /// </summary>
        /// <param name="builder">Authentication builder</param>
        public void Configure(AuthenticationBuilder builder, IConfiguration configuration)
        {
            builder.AddGoogle(GoogleDefaults.AuthenticationScheme, options =>
            {
                var settings = new GoogleExternalAuthSettings();
                try
                {
                    var goSettings = new Repository <Setting>(DataSettingsHelper.ConnectionString()).Table.Where(x => x.Name.StartsWith("googleexternalauthsettings"));
                    settings.ClientKeyIdentifier = goSettings.FirstOrDefault(x => x.Name == "googleexternalauthsettings.clientkeyidentifier")?.Value;
                    settings.ClientSecret        = goSettings.FirstOrDefault(x => x.Name == "googleexternalauthsettings.clientsecret")?.Value;
                }
                catch { };

                options.ClientId     = !string.IsNullOrWhiteSpace(settings.ClientKeyIdentifier) ? settings.ClientKeyIdentifier : "000";
                options.ClientSecret = !string.IsNullOrWhiteSpace(settings.ClientSecret) ? settings.ClientSecret : "000";
                options.SaveTokens   = true;

                //handles exception thrown by external auth provider
                options.Events = new OAuthEvents()
                {
                    OnRemoteFailure = ctx =>
                    {
                        ctx.HandleResponse();
                        var errorMessage = ctx.Failure.Message;
                        var state        = ctx.Request.Query["state"].FirstOrDefault();
                        errorMessage     = WebUtility.UrlEncode(errorMessage);
                        ctx.Response.Redirect($"/google-signin-failed?error_message={errorMessage}");

                        return(Task.FromResult(0));
                    }
                };
            });
        }
コード例 #2
0
 public GoogleAuthenticationSettingsController(
     GoogleExternalAuthSettings googleExternalAuthSettings,
     ITranslationService translationService,
     IPermissionService permissionService,
     ISettingService settingService)
 {
     _googleExternalAuthSettings = googleExternalAuthSettings;
     _translationService         = translationService;
     _permissionService          = permissionService;
     _settingService             = settingService;
 }
 public PSGoogleAuthenticationController(GoogleExternalAuthSettings linkedInExternalAuthSettings,
                                         IExternalAuthenticationService externalAuthenticationService,
                                         ILocalizationService localizationService,
                                         IPermissionService permissionService,
                                         ISettingService settingService)
 {
     this._googleExternalAuthSettings    = linkedInExternalAuthSettings;
     this._externalAuthenticationService = externalAuthenticationService;
     this._localizationService           = localizationService;
     this._permissionService             = permissionService;
     this._settingService = settingService;
 }
コード例 #4
0
 public GoogleProviderAuthorizer(
     IExternalAuthorizer authorizer,
     ExternalAuthenticationSettings externalAuthenticationSettings,
     GoogleExternalAuthSettings googleExternalAuthSettings,
     HttpContextBase httpContext,
     IWebHelper webHelper)
 {
     this._authorizer = authorizer;
     this._externalAuthenticationSettings = externalAuthenticationSettings;
     this._googleExternalAuthSettings     = googleExternalAuthSettings;
     this._httpContext = httpContext;
     this._webHelper   = webHelper;
 }
コード例 #5
0
 public ExternalAuthGoogleController(GoogleExternalAuthSettings googleExternalAuthSettings,
                                     IExternalAuthenticationService externalAuthenticationService,
                                     ILocalizationService localizationService,
                                     IPermissionService permissionService,
                                     ISettingService settingService,
                                     IStoreService storeService,
                                     IWorkContext workContext
                                     )
 {
     _googleExternalAuthSettings    = googleExternalAuthSettings;
     _externalAuthenticationService = externalAuthenticationService;
     _localizationService           = localizationService;
     _permissionService             = permissionService;
     _settingService = settingService;
 }
 public GoogleAuthenticationController(GoogleExternalAuthSettings googleExternalAuthSettings,
                                       IAuthenticationPluginManager authenticationPluginManager,
                                       IExternalAuthenticationService externalAuthenticationService,
                                       ILocalizationService localizationService,
                                       INotificationService notificationService,
                                       IOptionsMonitorCache <GoogleOptions> optionsCache,
                                       IPermissionService permissionService,
                                       ISettingService settingService,
                                       IStoreContext storeContext,
                                       IWorkContext workContext)
 {
     _googleExternalAuthSettings    = googleExternalAuthSettings;
     _authenticationPluginManager   = authenticationPluginManager;
     _externalAuthenticationService = externalAuthenticationService;
     _localizationService           = localizationService;
     _notificationService           = notificationService;
     _optionsCache      = optionsCache;
     _permissionService = permissionService;
     _settingService    = settingService;
     _storeContext      = storeContext;
     _workContext       = workContext;
 }
コード例 #7
0
        /// <summary>
        /// Configure
        /// </summary>
        /// <param name="builder">Authentication builder</param>
        public void AddAuthentication(AuthenticationBuilder builder, IConfiguration configuration)
        {
            builder.AddGoogle(GoogleDefaults.AuthenticationScheme, options =>
            {
                var connection = DataSettingsManager.LoadSettings();

                var settings = new GoogleExternalAuthSettings();
                try
                {
                    var gSettings = new MongoRepository <Setting>(connection.ConnectionString).Table.Where(x => x.Name.StartsWith("googleexternalauthsettings"));
                    if (gSettings.Any())
                    {
                        var metadata = gSettings.FirstOrDefault().Metadata;
                        settings     = JsonSerializer.Deserialize <GoogleExternalAuthSettings>(metadata);
                    }
                }
                catch (Exception ex) { Log.Error(ex, "AddGoogle"); };

                options.ClientId     = !string.IsNullOrWhiteSpace(settings.ClientKeyIdentifier) ? settings.ClientKeyIdentifier : "000";
                options.ClientSecret = !string.IsNullOrWhiteSpace(settings.ClientSecret) ? settings.ClientSecret : "000";
                options.SaveTokens   = true;

                //handles exception thrown by external auth provider
                options.Events = new OAuthEvents()
                {
                    OnRemoteFailure = ctx =>
                    {
                        ctx.HandleResponse();
                        var errorMessage = ctx.Failure.Message;
                        var state        = ctx.Request.Query["state"].FirstOrDefault();
                        errorMessage     = WebUtility.UrlEncode(errorMessage);
                        ctx.Response.Redirect($"/google-signin-failed?error_message={errorMessage}");

                        return(Task.FromResult(0));
                    }
                };
            });
        }
コード例 #8
0
 public GoogleAuthenticationController(IExternalAuthenticationService externalAuthenticationService,
                                       GoogleExternalAuthSettings googleExternalAuthSettings)
 {
     _externalAuthenticationService = externalAuthenticationService;
     _googleExternalAuthSettings    = googleExternalAuthSettings;
 }