/// <summary> /// Initializes a new instance of the <see cref="AppleTokenGenerator"/> class. /// </summary> /// <param name="authSetting">Your subscription identifier present in the membership section in your apple developer account</param> /// <param name="tokenGenerator">Generator of the jwt tokens</param> /// <param name="httpClient"></param> public AppleAuthClient(AppleAuthSetting authSetting, IAppleTokenGenerator tokenGenerator, HttpClient httpClient) { _authSetting = Guard.Argument(authSetting, nameof(authSetting)).NotNull(); _tokenGenerator = Guard.Argument(tokenGenerator, nameof(tokenGenerator)).NotNull().Value; _httpClient = Guard.Argument(httpClient, nameof(httpClient)).NotNull(); _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded")); }
private static async Task <AppleAuthClient> CreateAppleClient(string p8Path) { var p8 = await File.ReadAllTextAsync(p8Path); var authSetting = new AppleAuthSetting(_settings.TeamId, _settings.ClientId, _settings.RedirectUri); var keySetting = new AppleKeySetting(_settings.KeyId, p8); return(new AppleAuthClient(authSetting, keySetting)); }
public IEnumerator <object[]> GetEnumerator() { var a = new AppleAuthSetting("a", "b", "https://apple.com"); var b = new AppleTokenGenerator("a", "b", new AppleKeySetting("a", "b")); var c = new HttpClient(); yield return(new object[] { a, b, null }); yield return(new object[] { a, null, c }); yield return(new object[] { null, b, c }); }
public void GetLoginUri_CreateAlwaysANewState() { var handlerStub = new DelegatingHandlerStub(null); var settings = new AppleAuthSetting("a", "b", "https://apple.com", "x y z"); var client = GetClient(settings, handlerStub); var result1 = client.GetLoginUri(); var result2 = client.GetLoginUri(); var query1 = System.Web.HttpUtility.ParseQueryString(result1.Query); var query2 = System.Web.HttpUtility.ParseQueryString(result2.Query); query1.Get("state").Should().NotBe(query2.Get("state")); }
public void GetLoginUri_CreateWithRightQuery() { var handlerStub = new DelegatingHandlerStub(null); var settings = new AppleAuthSetting("a", "b", "https://apple.com", "x y z"); var client = GetClient(settings, handlerStub); var result = client.GetLoginUri(); var query = System.Web.HttpUtility.ParseQueryString(result.Query); query.AllKeys.Should().BeEquivalentTo("response_type", "client_id", "redirect_uri", "state", "scope", "response_mode"); query.Get("response_type").Should().Be("code id_token"); query.Get("client_id").Should().Be("b"); query.Get("redirect_uri").Should().Be("https://apple.com"); query.Get("scope").Should().Be("x y z"); query.Get("response_mode").Should().Be("form_post"); result.ToString().Should().Contain("redirect_uri=https%3a%2f%2fapple.com"); }
/// <summary> /// Initializes a new instance of the <see cref="AppleTokenGenerator"/> class. /// </summary> /// <param name="authSetting">Your subscription identifier present in the membership section in your apple developer account</param> /// <param name="tokenGenerator">Generator of the jwt tokens</param> public AppleAuthClient(AppleAuthSetting authSetting, IAppleTokenGenerator tokenGenerator) : this(authSetting, tokenGenerator, new HttpClient()) { }
/// <summary> /// Initializes a new instance of the <see cref="AppleTokenGenerator"/> class. /// </summary> /// <param name="authSetting">Your subscription identifier present in the membership section in your apple developer account</param> /// <param name="appleKeySetting">Informations of the key created for the "Sign in with Apple" feature</param> /// <param name="httpClient"></param> public AppleAuthClient(AppleAuthSetting authSetting, AppleKeySetting appleKeySetting, HttpClient httpClient) : this(authSetting, new AppleTokenGenerator(authSetting.TeamId, authSetting.ClientId, appleKeySetting), httpClient) { }
public void AppleAuthClient_NotValidArgument_ThrowArgumentException(AppleAuthSetting authSetting, IAppleTokenGenerator privateKeySetting, HttpClient httpClient) { FluentActions.Invoking(() => new AppleAuthClient(authSetting, privateKeySetting, httpClient)).Should().Throw <ArgumentException>(); }
private AppleAuthClient GetClient(AppleAuthSetting appleAuthSetting, DelegatingHandler handler) { return(new AppleAuthClient(appleAuthSetting, _appleTokenGeneratorMock.Object, new HttpClient(handler))); }