public static async Task ValidateAsync_WrongAudience() { AuthenticationSettings authenticationSettings = new() { Google = new GoogleAuthenticationSettings { ClientId = ClientId, }, }; IOptions <AuthenticationSettings> options = Options.Create(authenticationSettings); using (HttpClientTestingFactory http = new()) { GoogleAssertionGrantHandler handler = new(options, http.HttpClient); Task <AssertionGrantResult> resultTask = handler.ValidateAsync(Assertion); http.Expect(ValidationEndpoint).Respond(JsonConvert.SerializeObject(new JsonWebToken { Aud = "SomeOtherClientId", Sub = ExternalUserId, })); AssertionGrantResult result = await resultTask; Assert.NotNull(result); Assert.False(result.IsSuccessful); http.EnsureNoOutstandingRequests(); } }
public bool CheckSettings(GoogleAuthenticationSettings settings) { var obj = new GoogleAuthenticationSettingsViewModel() { ClientID = settings.ClientID, CallbackPath = settings.CallbackPath, ClientSecret = settings.ClientSecret }; var vc = new ValidationContext(obj); return(Validator.TryValidateObject(obj, vc, ImmutableArray.CreateBuilder <ValidationResult>())); }
public async Task UpdateSettingsAsync(GoogleAuthenticationSettings settings) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } var container = await _siteService.LoadSiteSettingsAsync(); container.Alter <GoogleAuthenticationSettings>(nameof(GoogleAuthenticationSettings), aspect => { aspect.ClientID = settings.ClientID; aspect.ClientSecret = settings.ClientSecret; aspect.CallbackPath = settings.CallbackPath; }); await _siteService.UpdateSiteSettingsAsync(container); }