public void Configure(string name, GoogleOptions options) { if (!string.Equals(name, GoogleDefaults.AuthenticationScheme, StringComparison.Ordinal)) { return; } if (!ValidSettings()) { return; } options.ClientId = _platoGoogleOptions.ClientId; options.ClientSecret = _platoGoogleOptions.ClientSecret; if (_platoGoogleOptions.CallbackPath.HasValue) { options.CallbackPath = _platoGoogleOptions.CallbackPath; } options.UserInformationEndpoint = "https://www.googleapis.com/oauth2/v2/userinfo"; options.ClaimActions.Clear(); options.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id"); options.ClaimActions.MapJsonKey(ClaimTypes.Name, "name"); options.ClaimActions.MapJsonKey(ClaimTypes.GivenName, "given_name"); options.ClaimActions.MapJsonKey(ClaimTypes.Surname, "family_name"); options.ClaimActions.MapJsonKey("urn:google:profile", "link"); options.ClaimActions.MapJsonKey(ClaimTypes.Email, "email"); }
public async Task <IActionResult> Create(AuthenticationViewModel model) { if (ModelState.IsValid) { OAuthOptions oAuthOptions; if (HandlerHelper.GetProviderName(model.HandlerType) == "Google") { oAuthOptions = new GoogleOptions(); } else { oAuthOptions = new OAuthOptions(); } oAuthOptions.ClientId = model.ClientId; oAuthOptions.ClientSecret = model.ClientSecret; oAuthOptions.CallbackPath = "/signin-" + model.Scheme; await _manager.AddAsync(new SchemeDefinition { Scheme = model.Scheme, DisplayName = model.DisplayName, HandlerType = _manager.ManagedHandlerType.First(t => t.Name == model.HandlerType), Options = oAuthOptions }); return(RedirectToAction("List")); } return(View(model)); }
public TenantMiddleware( RequestDelegate next, IAuthenticationSchemeProvider oauthProvider, IMemoryCache memoryCache, IdentityServerOptions identityServerOptions, //JwtBearerOptions jwtBearerOptions, IOptionsMonitor <MicrosoftAccountOptions> microsoftOptions, IOptionsMonitor <GoogleOptions> googleOptions, IOptionsMonitor <FacebookOptions> facebookOptions, IOptionsMonitor <GitHubAuthenticationOptions> githubOptions, IOptionsMonitor <QQAuthenticationOptions> qqOptions, IOptionsMonitor <WeiboAuthenticationOptions> weiboOptions, IOptionsMonitor <WeixinAuthenticationOptions> weixinOptions ) { _next = next; _oauthProvider = oauthProvider; _memoryCache = memoryCache; _identityServerOptions = identityServerOptions; //_jwtBearerOptions = jwtBearerOptions; _microsoftOptions = microsoftOptions.Get(MicrosoftAccountDefaults.AuthenticationScheme); _googleOptions = googleOptions.Get(GoogleDefaults.AuthenticationScheme); _facebookOptions = facebookOptions.Get(FacebookDefaults.AuthenticationScheme); _githubOptions = githubOptions.Get(GitHubAuthenticationDefaults.AuthenticationScheme); _qqOptions = qqOptions.Get(QQAuthenticationDefaults.AuthenticationScheme); _weiboOptions = weiboOptions.Get(WeiboAuthenticationDefaults.AuthenticationScheme); _weixinOptions = weixinOptions.Get(WeixinAuthenticationDefaults.AuthenticationScheme); }
public void Configure(string name, GoogleOptions options) { if (!string.Equals(name, GoogleDefaults.AuthenticationScheme)) { return; } var settings = GetGoogleAuthenticationSettingsAsync().GetAwaiter().GetResult(); options.ClientId = settings?.ClientID ?? string.Empty; try { options.ClientSecret = _dataProtectionProvider.CreateProtector(GoogleConstants.Features.GoogleAuthentication).Unprotect(settings.ClientSecret); } catch { _logger.LogError("The Consumer Secret could not be decrypted. It may have been encrypted using a different key."); } if (settings.CallbackPath.HasValue) { options.CallbackPath = settings.CallbackPath; } options.SaveTokens = settings.SaveTokens; }
private void SetGoogleOptions(GoogleOptions options) { options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme; options.ClientId = Configuration.GetSection("GoogleClientIdAndSecret")["ClientId"]; options.ClientSecret = Configuration.GetSection("GoogleClientIdAndSecret")["ClientSecret"]; }
private static Activity RequestToActivity(Payload actionPayload, GoogleOptions googleOptions) { var activity = new Activity { ChannelId = "google", ServiceUrl = $"", Recipient = new ChannelAccount("", "action"), From = new ChannelAccount(actionPayload.User.UserId, "user"), Conversation = new ConversationAccount(false, "conversation", $"{actionPayload.Conversation.ConversationId}"), Type = ActivityTypes.Message, Text = StripInvocation(actionPayload.Inputs[0]?.RawInputs[0]?.Query, googleOptions.ActionInvocationName), Id = new Guid().ToString(), Timestamp = DateTime.UtcNow, Locale = actionPayload.User.Locale }; if (actionPayload.Inputs.FirstOrDefault()?.Arguments?.FirstOrDefault()?.Name == "OPTION") { activity.Text = actionPayload.Inputs.First().Arguments.First().TextValue; } activity.ChannelData = actionPayload; return(activity); }
async public Task test_configureOptions() { var host = WebHost.CreateDefaultBuilder() .ConfigureServices(srv => srv .AddSingleton(p => p.GetService <WebHostBuilderContext>().Configuration) .AddSingleton(typeof(IConfigureOptions <>), typeof(ConfigurationConfigureOptions <>)) .AddSingleton <IPostConfigureOptions <GoogleOptions>, ConfigurationConfigureOptions <GoogleOptions> >() .AddOptions() .AddAuthentication() .AddGoogle()) .Configure(app => app.Use( next => ctx => { var google = new GoogleOptions(); var ss = ctx.RequestServices.GetServices <IPostConfigureOptions <GoogleOptions> >(); ctx.Response.WriteAsync(ctx.RequestServices.GetService <IOptionsSnapshot <GoogleOptions> >().Get(string.Empty).ClientId); ctx.Response.WriteAsync(ctx.RequestServices.GetService <IOptionsSnapshot <GoogleOptions> >().Get("Google").ClientId); ctx.Response.WriteAsync(ctx.RequestServices.GetService <IOptionsFactory <GoogleOptions> >().Create(string.Empty).ClientId); ctx.Response.WriteAsync(ctx.RequestServices.GetService <IOptionsFactory <GoogleOptions> >().Create("Google").ClientId); return(Task.CompletedTask); })); var result = await new TestServer(host).CreateRequest("/").GetAsync(); var actual = await result.Content.ReadAsStringAsync(); Assert.NotEqual(string.Empty, actual); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseIdentity(); // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715 var facebookOptions = new FacebookOptions() { AppId = Configuration["Authentication:Facebook:AppId"], AppSecret = Configuration["Authentication:Facebook:AppSecret"] }; facebookOptions.Fields.Add("email"); facebookOptions.Fields.Add("first_name"); facebookOptions.Fields.Add("last_name"); app.UseFacebookAuthentication(facebookOptions); var googleOptions = new GoogleOptions() { ClientId = Configuration["Authentication:Google:ClientId"], ClientSecret = Configuration["Authentication:Google:ClientSecret"], Scope = { "email", "openid" } }; app.UseGoogleAuthentication(googleOptions); var microsoftAccountOptions = new MicrosoftAccountOptions() { ClientId = Configuration["Authentication:MicrosoftAccount:ClientId"], ClientSecret = Configuration["Authentication:MicrosoftAccount:ClientSecret"] }; app.UseMicrosoftAccountAuthentication(microsoftAccountOptions); app.UseMvc(routes => { routes.MapRoute(name: "areaRoute", template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStatusCodePagesWithReExecute("/Status/Status/{0}"); app.UseStaticFiles(); app.UseIdentity(); var googleClientId = Configuration["Authentication:Google:ClientId"]; var googleClientSecret = Configuration["Authentication:Google:ClientSecret"]; if (!string.IsNullOrEmpty(googleClientId) && !string.IsNullOrEmpty(googleClientSecret)) { var options = new GoogleOptions(); options.ClientId = googleClientId; options.ClientSecret = googleClientSecret; options.Scope.Add("email"); options.Scope.Add("profile"); } var facebookAppId = Configuration["Authentication:Facebook:AppId"]; var facebookAppSecret = Configuration["Authentication:Facebook:AppSecret"]; if (!string.IsNullOrEmpty(facebookAppId) && !string.IsNullOrEmpty(facebookAppSecret)) { app.UseFacebookAuthentication(new FacebookOptions { AppId = facebookAppId, AppSecret = facebookAppSecret }); } app.UseJsEngine(); app.UseMvc(routes => { MapRouteRouteBuilderExtensions.MapRoute(routes, name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); app.Use((context, next) => { context.Response.StatusCode = 404; return(next()); }); }
public static IApplicationBuilder UseGoogleAuthentication(this IApplicationBuilder app, Action <GoogleOptions> configuration) { GoogleOptions options = new GoogleOptions(); configuration(options); app.UseGoogleAuthentication(options); return(app); }
public ExternalLoginService(IOptions <OpenIdOptions> openIdOptionsAccessor, ICacheService cacheService, IOptions <GoogleOptions> googleOptionsAccessor, IOptions <FacebookOptions> facebookOptionsAccessor) { _cacheService = cacheService; _openIdOptions = openIdOptionsAccessor.Value; _googleOptions = googleOptionsAccessor.Value; _facebookOptions = facebookOptionsAccessor.Value; }
/// <summary> /// Authenticate users using Google OAuth 2.0. /// </summary> /// <param name="app">The <see cref="IApplicationBuilder"/> passed to the configure method.</param> /// <param name="configureOptions">Used to configure Middleware options.</param> /// <param name="optionsName">Name of the options instance to be used</param> /// <returns>The updated <see cref="IApplicationBuilder"/>.</returns> public static IApplicationBuilder UseGoogleAuthentication([NotNull] this IApplicationBuilder app, Action <GoogleOptions> configureOptions) { var options = new GoogleOptions(); if (configureOptions != null) { configureOptions(options); } return(app.UseGoogleAuthentication(options)); }
public async Task AddAsync_should_add_google_handler() { var eventCalled = false; Task onCreatingTicket(OAuthCreatingTicketContext context) { eventCalled = true; return(Task.CompletedTask); } var provider = CreateServiceProvider(options => { options.AddGoogle(configure => { configure.Events.OnCreatingTicket = onCreatingTicket; }); }); var sut = provider.GetRequiredService <AuthenticationSchemeProviderWrapper>(); Assert.Contains(typeof(GoogleHandler), sut.GetManagedHandlerTypes()); var googleOptions = new GoogleOptions { ClientId = "test", ClientSecret = "test" }; var scheme = Guid.NewGuid().ToString(); var definition = new TSchemeDefinition { Scheme = scheme, DisplayName = "test", HandlerType = typeof(GoogleHandler), Options = googleOptions }; await sut.AddAsync(definition); var state = await VerifyAddedAsync <GoogleOptions>(scheme, provider); var httpContext = new Mock <HttpContext>().Object; state.options.Events.OnCreatingTicket(new OAuthCreatingTicketContext( new ClaimsPrincipal(), new AuthenticationProperties(), httpContext, state.scheme as AuthenticationScheme, state.options as GoogleOptions, new HttpClient(), OAuthTokenResponse.Failed(new Exception()), JsonDocument.Parse("{ \"name\": \"test\"}").RootElement)); Assert.True(eventCalled); }
public MultiTenantGoogleOptionsResolver( GoogleOptions originalOptions, ISiteResolver siteResolver, ISiteRepository siteRepository, MultiTenantOptions multiTenantOptions) { this.originalOptions = originalOptions; this.siteResolver = siteResolver; this.multiTenantOptions = multiTenantOptions; siteRepo = siteRepository; }
public MultiTenantGoogleOptionsResolver( GoogleOptions originalOptions, //ISiteResolver siteResolver, //ISiteRepository siteRepository, ISiteSettings currentSite, MultiTenantOptions multiTenantOptions) { this.originalOptions = originalOptions; //this.siteResolver = siteResolver; this.multiTenantOptions = multiTenantOptions; //siteRepo = siteRepository; site = currentSite; }
public OAuthRepository( ILogger <SessionRepository> logger, SignInManager <ApplicationUser> signInManager, UserManager <ApplicationUser> userManager, IOptionsMonitor <GoogleOptions> googleOptionsMonitor, IOptionsMonitor <FacebookOptions> facebookOptionsMonitor) { logger_ = logger; signInManager_ = signInManager; userManager_ = userManager; googleOptions_ = googleOptionsMonitor.Get(GoogleDefaults.AuthenticationScheme); facebookOptions_ = facebookOptionsMonitor.Get(FacebookDefaults.AuthenticationScheme); }
public static IApplicationBuilder UseExternalAuth(this IApplicationBuilder application, IConfigurationRoot configuration) { var externalCookieScheme = application.ApplicationServices.GetRequiredService <IOptions <IdentityOptions> >().Value.Cookies.ExternalCookieAuthenticationScheme; // or use var facebookOptions = new FacebookOptions { AuthenticationScheme = "facebook", DisplayName = "Facebook", SignInScheme = externalCookieScheme, AppId = configuration["Auth:Facebook:AppId"], AppSecret = configuration["Auth:Facebook:AppSecret"], SaveTokens = true, Events = new OAuthEvents { OnCreatingTicket = async context => { var payload = await GetUserInfo(context); JsonKeyClaim claims = new JsonKeyClaim(context.Identity, payload, context.Options.ClaimsIssuer); claims.TryAddClaimByJsonKey("urn:facebook:photo", "picture"); } } }; var gooleOptions = new GoogleOptions { AuthenticationScheme = "google", DisplayName = "Google", SignInScheme = externalCookieScheme, ClientId = configuration["Auth:Google:ClientId"], ClientSecret = configuration["Auth:Google:ClientSecret"], SaveTokens = true, Events = new OAuthEvents { OnCreatingTicket = async context => { var payload = await GetUserInfo(context); JsonKeyClaim claims = new JsonKeyClaim(context.Identity, payload, context.Options.ClaimsIssuer); claims.TryAddClaimByJsonSubKey("urn:google:photo", "image", "url"); claims.TryAddClaimByJsonKey(ClaimTypes.Locality, "language"); claims.TryAddClaimByJsonSubKey("urn:google:location", "location", "name"); } } }; return(application // Add external authentication middleware below. To configure them please see https://go.microsoft.com/fwlink/?LinkID=532715 .UseFacebookAuthentication(facebookOptions) .UseGoogleAuthentication(gooleOptions)); }
public TenantMiddleware( RequestDelegate next, TenantService tenantService, IAuthenticationSchemeProvider oauthProvider, IMemoryCache memoryCache, IdentityServerOptions identityServerOptions, IOptionsMonitor <AmazonAuthenticationOptions> amazonOptions, IOptionsMonitor <FacebookOptions> facebookOptions, IOptionsMonitor <GitHubOptions> githubOptions, IOptionsMonitor <GitterAuthenticationOptions> gitterOptions, IOptionsMonitor <GoogleOptions> googleOptions, IOptionsMonitor <InstagramAuthenticationOptions> instagramOptions, IOptionsMonitor <LinkedInAuthenticationOptions> linkedinOptions, IOptionsMonitor <MicrosoftAccountOptions> microsoftOptions, IOptionsMonitor <PaypalAuthenticationOptions> paypalOptions, IOptionsMonitor <QQOptions> qqOptions, IOptionsMonitor <RedditAuthenticationOptions> redditOptions, IOptionsMonitor <SalesforceAuthenticationOptions> salesforceOptions, IOptionsMonitor <TwitterOptions> twitterOptions, IOptionsMonitor <VisualStudioAuthenticationOptions> visualstudioOptions, IOptionsMonitor <WeiboOptions> weiboOptions, IOptionsMonitor <WeixinOptions> weixinOptions, IOptionsMonitor <WordPressAuthenticationOptions> wordpressOptions ) { _next = next; _tenantService = tenantService; _oauthProvider = oauthProvider; _memoryCache = memoryCache; _identityServerOptions = identityServerOptions; _amazonOptions = amazonOptions.CurrentValue; _facebookOptions = facebookOptions.CurrentValue; _githubOptions = githubOptions.CurrentValue; _gitterOptions = gitterOptions.CurrentValue; _googleOptions = googleOptions.CurrentValue; _instagramOptions = instagramOptions.CurrentValue; _linkedinOptions = linkedinOptions.CurrentValue; _microsoftOptions = microsoftOptions.CurrentValue; _paypalOptions = paypalOptions.CurrentValue; _qqOptions = qqOptions.CurrentValue; _redditOptions = redditOptions.CurrentValue; _salesforceOptions = salesforceOptions.CurrentValue; _twitterOptions = twitterOptions.CurrentValue; _visualstudioOptions = visualstudioOptions.CurrentValue; _weiboOptions = weiboOptions.CurrentValue; _weixinOptions = weixinOptions.CurrentValue; _wordpressOptions = wordpressOptions.CurrentValue; }
/// <summary> /// Add Google authentication to the application. /// </summary> /// <param name="app">Current application request pipeline.</param> /// <param name="configuration">The configuration object from which to get <c>ClientId</c> and <c>ClientSecret</c>.</param> public static void AddGoogleAuthentication(this IApplicationBuilder app, IConfigurationRoot configuration) { string googleClientId = configuration["Authentication:Google:GoogleClientId"]; string googleClientSecret = configuration["Authentication:Google:GoogleClientSecret"]; var googleOptions = new GoogleOptions { ClientId = googleClientId, ClientSecret = googleClientSecret }; if (googleOptions.IsConfigurationValid()) { app.UseGoogleAuthentication(googleOptions); } }
void ConfigureGoogleAuthOptions(GoogleOptions opts) { // https://github.com/aspnet/AspNetCore/issues/6486 opts.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme; opts.ClientId = _config["GooglePlus:ClientId"]; opts.ClientSecret = _config["GooglePlus:ClientSecret"]; opts.UserInformationEndpoint = "https://www.googleapis.com/oauth2/v2/userinfo"; opts.ClaimActions.Clear(); opts.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id"); opts.ClaimActions.MapJsonKey(ClaimTypes.Name, "name"); opts.ClaimActions.MapJsonKey(ClaimTypes.GivenName, "given_name"); opts.ClaimActions.MapJsonKey(ClaimTypes.Surname, "family_name"); opts.ClaimActions.MapJsonKey("urn:google:profile", "link"); opts.ClaimActions.MapJsonKey(ClaimTypes.Email, "email"); }
/// <summary> /// Adds the <see cref="GoogleMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables Google authentication capabilities. /// </summary> /// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param> /// <param name="configureOptions">An action delegate to configure the provided <see cref="GoogleOptions"/>.</param> /// <returns>A reference to this instance after the operation has completed.</returns> public static IApplicationBuilder UseGoogleAuthentication(this IApplicationBuilder app, Action <GoogleOptions> configureOptions) { if (app == null) { throw new ArgumentNullException(nameof(app)); } var options = new GoogleOptions(); if (configureOptions != null) { configureOptions(options); } return(app.UseGoogleAuthentication(options)); }
public static IApplicationBuilder UseMultiTenantGoogleAuthentication( this IApplicationBuilder app, Action <GoogleOptions> configureOptions) { //https://github.com/aspnet/Security/blob/582f562bbb20fc76f37023086e2b2d861eb4d43d/src/Microsoft.AspNet.Authentication.Google/GoogleOptions.cs //https://github.com/aspnet/Security/blob/582f562bbb20fc76f37023086e2b2d861eb4d43d/src/Microsoft.AspNet.Authentication.Google/GoogleDefaults.cs var options = new GoogleOptions(); if (configureOptions != null) { configureOptions(options); } return(app.UseMiddleware <MultiTenantGoogleMiddleware>(options)); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } //TemplateConfig(app, env, loggerFactory); app.UseDeveloperExceptionPage(); app.UseStaticFiles(); app.UseIdentity(); app.UseCookieAuthentication(new CookieAuthenticationOptions() { LoginPath = "/account/login", AuthenticationScheme = "Cookies", AutomaticAuthenticate = true, AutomaticChallenge = true, ExpireTimeSpan = new TimeSpan(1, 0, 0, 0, 0), Events = new CookieAuthenticationEvents() { OnRedirectToLogin = ctx => { if (ctx.Request.Headers["TwinPairs.Api"] == "V1.0" && ctx.Response.StatusCode == (int)HttpStatusCode.OK) { ctx.Response.Clear(); ctx.Response.StatusCode = (int)HttpStatusCode.Forbidden; } else { ctx.Response.Redirect(ctx.RedirectUri); } return(Task.FromResult(0)); } } }); var googleOptions = new GoogleOptions(); googleOptions.ClientId = this.Configuration["client_id"]; googleOptions.ClientSecret = this.Configuration["client_secret"]; app.UseGoogleAuthentication(googleOptions); app.UseMvcWithDefaultRoute(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseIdentity(); // Add external authentication middleware below. To configure them please see https://go.microsoft.com/fwlink/?LinkID=532715 var googleOptions = new GoogleOptions() { ClientId = "262758676909-hg9lrv1o3co1r92r08hmcse1aamg3lfu.apps.googleusercontent.com", ClientSecret = "ypFrtiiWdxGiXYxEJkOfH25S", AccessType = "offline", SaveTokens = true }; googleOptions.Scope.Add("openid"); googleOptions.Scope.Add("profile"); googleOptions.Scope.Add("email"); googleOptions.Scope.Add("https://www.googleapis.com/auth/drive"); googleOptions.Scope.Add("https://www.googleapis.com/auth/spreadsheets.readonly"); app.UseGoogleAuthentication(googleOptions); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
public static IServiceCollection AddGoogleAuth(this IServiceCollection services, IConfiguration configuration) { services.Configure <GoogleOptions>(configuration.GetSection("Authentication:Google")); services.AddScoped <GoogleAuth>(); services.AddBlazoredLocalStorage(); services.AddHttpClient("google", client => { var config = new GoogleOptions(); configuration.GetSection("Authentication:Google").Bind(config); client.BaseAddress = new Uri(config.ApiBaseAddress); }) .AddTypedClient(RestService.For <IGoogleRequests>); return(services); }
public static IApplicationBuilder UseMyGoogleAuthentication(this IApplicationBuilder app) { var options = app.ApplicationServices.GetService <IOptions <MyIdentityOptions> >().Value; if (options.IsGoogleAuthConfigured()) { var googleOptions = new GoogleOptions { ClientId = options.GoogleClient, ClientSecret = options.GoogleSecret, Events = new GoogleHandler() }; app.UseGoogleAuthentication(googleOptions); } return(app); }
public static IApplicationBuilder UseMyGoogleAuthentication(this IApplicationBuilder app) { var options = app.ApplicationServices.GetService <IOptions <MyIdentityOptions> >().Value; if (!string.IsNullOrWhiteSpace(options.GoogleClient) && !string.IsNullOrWhiteSpace(options.GoogleSecret)) { var googleOptions = new GoogleOptions { Events = new GoogleHandler(), ClientId = options.GoogleClient, ClientSecret = options.GoogleSecret }; app.UseGoogleAuthentication(googleOptions); } return(app); }
internal static void SeedProviders(IConfiguration configuration, PersistentDynamicManager <SchemeDefinition> persistentDynamicManager) { var googleDefinition = persistentDynamicManager.FindBySchemeAsync("Google").GetAwaiter().GetResult(); if (googleDefinition == null) { var options = new GoogleOptions { ClientId = configuration.GetValue <string>("Google:ClientId"), ClientSecret = configuration.GetValue <string>("Google:ClientSecret"), }; persistentDynamicManager.AddAsync(new SchemeDefinition { Scheme = "Google", DisplayName = "Google", HandlerType = persistentDynamicManager.ManagedHandlerType.First(t => t.Name == "GoogleHandler"), Options = options }).ConfigureAwait(false); } }
private void InitGoogleAuthentication(IApplicationBuilder app, ILogger logger) { string googleClientId = Configuration[Config.GOOGLE_CLIENT_ID]; string googleClientSecret = Configuration[Config.GOOGLE_CLIENT_SECRET]; if (!string.IsNullOrWhiteSpace(googleClientId) && !string.IsNullOrWhiteSpace(googleClientSecret)) { var googleOptions = new GoogleOptions { ClientId = googleClientId, ClientSecret = googleClientSecret }; app.UseGoogleAuthentication(googleOptions); } else { logger.LogWarning("Google external authentication credentials not set."); } }
public async Task <GoogleResponseBody> ProcessActivity(Payload actionPayload, GoogleOptions googleOptions, BotCallbackHandler callback) { TurnContext context = null; try { Options = googleOptions; var activity = RequestToActivity(actionPayload, googleOptions); BotAssert.ActivityNotNull(activity); context = new TurnContext(this, activity); Responses = new Dictionary <string, List <Activity> >(); await base.RunPipelineAsync(context, callback, default(CancellationToken)).ConfigureAwait(false); var key = $"{activity.Conversation.Id}:{activity.Id}"; try { GoogleResponseBody response = null; var activities = Responses.ContainsKey(key) ? Responses[key] : new List <Activity>(); response = CreateResponseFromLastActivity(activities, context); return(response); } finally { if (Responses.ContainsKey(key)) { Responses.Remove(key); } } } catch (Exception ex) { await googleOptions.OnTurnError(context, ex); throw; } }