public async Task WhenTheClientGrantTypeIsNotSupportedThenAnErrorIsReturned() { const string clientId = "clientId"; const string scope = "scope"; var authorizationParameter = new AuthorizationParameter { ResponseType = ResponseTypeNames.Code, RedirectUrl = new Uri(HttpsLocalhost), ClientId = clientId, Scope = scope, Claims = new ClaimsParameter() }; var client = new Client { GrantTypes = new[] { GrantTypes.ClientCredentials }, AllowedScopes = new[] { scope }, RedirectionUrls = new[] { new Uri(HttpsLocalhost), } }; var result = await _getAuthorizationCodeOperation.Execute( authorizationParameter, new ClaimsPrincipal(), client, "", CancellationToken.None) .ConfigureAwait(false); Assert.NotNull(result); Assert.Equal(ErrorCodes.InvalidRequest, result.Error !.Title); Assert.Equal( string.Format(Strings.TheClientDoesntSupportTheGrantType, clientId, "authorization_code"), result.Error.Detail); }
public async Task When_Passing_Valid_Request_Then_ReturnsRedirectInstruction() { const string clientId = "clientId"; const string scope = "scope"; var client = new Client { ResponseTypes = new[] { ResponseTypeNames.Code }, AllowedScopes = new[] { scope }, RedirectionUrls = new[] { new Uri(HttpsLocalhost), } }; var authorizationParameter = new AuthorizationParameter { ResponseType = ResponseTypeNames.Code, RedirectUrl = new Uri(HttpsLocalhost), ClientId = clientId, Scope = scope, Claims = null }; var result = await _getAuthorizationCodeOperation .Execute(authorizationParameter, new ClaimsPrincipal(), client, null, CancellationToken.None) .ConfigureAwait(false); Assert.NotNull(result.RedirectInstruction); }
public async Task <Shared.Models.Client> GetClientData(string id) { try { DocumentReference docRef = firestoreDb.Collection("Clients").Document(id); DocumentSnapshot snapshot = await docRef.GetSnapshotAsync(); if (snapshot.Exists) { Dictionary <string, object> client = snapshot.ToDictionary(); string json = JsonConvert.SerializeObject(client); Shared.Models.Client clientById = JsonConvert.DeserializeObject <Shared.Models.Client>(json); clientById.Id = snapshot.Id; clientById.Date = snapshot.CreateTime.Value.ToDateTimeOffset(); return(clientById); } else { return(new Shared.Models.Client()); } } catch (Exception) { throw; } }
public async Task When_Requesting_Authorization_With_Valid_Request_Then_ReturnsRedirectInstruction() { const string clientId = "clientId"; const string scope = "openid"; var authorizationParameter = new AuthorizationParameter { ResponseType = ResponseTypeNames.Token, State = "state", Nonce = "nonce", ClientId = clientId, Scope = scope, Claims = null, RedirectUrl = new Uri("https://localhost") }; var claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim("sub", "test") }, "fake")); var client = new Client { ResponseTypes = ResponseTypeNames.All, RedirectionUrls = new[] { new Uri("https://localhost"), }, GrantTypes = new[] { GrantTypes.Implicit }, AllowedScopes = new[] { "openid" } }; var result = await _getTokenViaImplicitWorkflowOperation.Execute( authorizationParameter, claimsPrincipal, client, null, CancellationToken.None) .ConfigureAwait(false); Assert.NotNull(result.RedirectInstruction); }
public async Task <List <Shared.Models.Client> > GetAllClients() { try { Query clientQuery = firestoreDb.Collection("Clients"); QuerySnapshot clientQuerySnapshot = await clientQuery.GetSnapshotAsync(); List <Shared.Models.Client> listClients = new List <Shared.Models.Client>(); foreach (DocumentSnapshot documentSnapshot in clientQuerySnapshot.Documents) { if (documentSnapshot.Exists) { Dictionary <string, object> client = documentSnapshot.ToDictionary(); string json = JsonConvert.SerializeObject(client); Shared.Models.Client newClient = JsonConvert.DeserializeObject <Shared.Models.Client>(json); newClient.Id = documentSnapshot.Id; newClient.Date = documentSnapshot.CreateTime.Value.ToDateTimeOffset(); listClients.Add(newClient); } } List <Shared.Models.Client> storedClientList = listClients.OrderBy(x => x.Date).ToList(); return(storedClientList); } catch (Exception) { throw; } }
public async void UpdateClient(Shared.Models.Client client) { try { DocumentReference updateclient = firestoreDb.Collection("Clients").Document(client.Id); await updateclient.SetAsync(client, SetOptions.Overwrite); } catch (Exception) { throw; } }
public async void AddClient(Shared.Models.Client client) { try { await firestoreDb .Collection("Clients") .Document(client.Id) .SetAsync(client); } catch (Exception) { throw; } }
public void PutClient([FromBody] Shared.Models.Client client) => objClient.UpdateClient(client);
public void PostClient([FromBody] Shared.Models.Client client) => objClient.AddClient(client);