public async Task success_appIdentityCreate_GET() { using (var graphQLHttpClient = new GraphQL.Client.GraphQLClient(_graphQLClientOptions)) { var appIdentityCreate = new GraphQLRequest(@"query q($input: appIdentityCreate!) { appIdentityCreate(input: $input){ authority expires_in id_token } }") { OperationName = null, Variables = new { input = new { appId = "myApp 001", machineId = "machineId 001" } } }; var graphQLResponse = await graphQLHttpClient.GetAsync(appIdentityCreate); graphQLResponse.ShouldNotBeNull(); var appIdentityResponse = graphQLResponse.GetDataFieldAs <AppIdentityResultModel>("appIdentityCreate"); //data->appIdentityCreate is casted as AppIdentityResponse appIdentityResponse.ShouldNotBeNull(); var handler = new JwtSecurityTokenHandler(); var tokenS = handler.ReadToken(appIdentityResponse.id_token) as JwtSecurityToken; tokenS.ShouldNotBeNull(); } }
public async Task success_graphQLDiscovery_GET() { using (var graphQLHttpClient = new GraphQL.Client.GraphQLClient(_graphQLClientOptions)) { var graphQlRequest = new GraphQLRequest(@"query{ graphQLDiscovery{ graphQLEndpoints{ name url } } }"); var graphQLResponse = await graphQLHttpClient.GetAsync(graphQlRequest); graphQLResponse.ShouldNotBeNull(); } }
public async Task success_graphQLDiscovery_GET() { using (var graphQLHttpClient = new GraphQL.Client.GraphQLClient(_graphQLClientOptions)) { var graphQlRequest = new GraphQLRequest(@"query{ graphQLDiscovery{ graphQLEndpoints{ name url } } }"); var graphQLResponse = await graphQLHttpClient.GetAsync(graphQlRequest); graphQLResponse.ShouldNotBeNull(); var graphQLDiscoveryModel = (GraphQLDiscoveryModel)graphQLResponse.GetDataFieldAs <GraphQLDiscoveryModel>("graphQLDiscovery"); //data->graphQLDiscovery is casted as GraphQLDiscoveryModel graphQLDiscoveryModel.ShouldNotBeNull(); graphQLDiscoveryModel.graphQLEndpoints.ShouldNotBeNull(); graphQLDiscoveryModel.graphQLEndpoints.Count.ShouldBeGreaterThan(0); } }
/// <summary> /// Send an IntrospectionQuery via GET /// </summary> /// <param name="graphQLClient">The GraphQLClient</param> /// <returns>The GraphQLResponse</returns> public static async Task <GraphQLResponse> GetIntrospectionQueryAsync(this GraphQLClient graphQLClient) => await graphQLClient.GetAsync(IntrospectionQuery).ConfigureAwait(false);
public async Task success_app_identity_bind_and_token_exchange_and_make_auth_call() { AppIdentityResultModel appIdentityResponse = null; using (var graphQLHttpClient = new GraphQL.Client.GraphQLClient(_graphQLClientOptions)) { var appIdentityCreate = new GraphQLRequest(@"query q($input: appIdentityCreate!) { appIdentityCreate(input: $input){ authority expires_in id_token } }") { OperationName = null, Variables = new { input = new { appId = "myApp 001", machineId = "machineId 001" } } }; var graphQLResponse = await graphQLHttpClient.PostAsync(appIdentityCreate); appIdentityResponse = (AppIdentityResultModel)graphQLResponse .GetDataFieldAs <AppIdentityResultModel>("appIdentityCreate"); //data->appIdentityCreate is casted as AppIdentityResponse appIdentityResponse.ShouldNotBeNull(); var handler = new JwtSecurityTokenHandler(); var tokenS = handler.ReadToken(appIdentityResponse.id_token) as JwtSecurityToken; tokenS.ShouldNotBeNull(); } /* * This next part fails because the validator calls out to authorities to get the public keys * The authority in the self case is under this TestServer and for some reason the discovery cache * cant reach this pretend http://localhost */ string access_token = ""; using (var graphQLHttpClient = new GraphQL.Client.GraphQLClient(_graphQLClientOptions)) { var appIdentityCreate = new GraphQLRequest(@"query q($input: tokenExchange!) { tokenExchange(input: $input){ authority access_token token_type httpHeaders{ name value } } }") { OperationName = null, Variables = new { input = new { tokens = new[] { new { token = appIdentityResponse.id_token, tokenScheme = "self" } }, exchange = "google-my-custom", extras = new[] { "a", "b", "c" } } } }; var graphQLResponse = await graphQLHttpClient.PostAsync(appIdentityCreate); graphQLResponse.ShouldNotBeNull(); var bindResponse = (List <TokenExchangeResponse>)graphQLResponse .GetDataFieldAs <List <TokenExchangeResponse> >("tokenExchange"); //data->appIdentityCreate is casted as AppIdentityResponse bindResponse.ShouldNotBeNull(); bindResponse.Count.ShouldBeGreaterThan(0); var handler = new JwtSecurityTokenHandler(); var tokenS = handler.ReadToken(bindResponse[0].access_token) as JwtSecurityToken; tokenS.ShouldNotBeNull(); access_token = bindResponse[0].access_token; } using (var graphQLHttpClient = new GraphQL.Client.GraphQLClient(_graphQLClientOptions)) { var graphQlRequest = new GraphQLRequest(@"query{ authRequired{ claims{ name value } } }") { }; graphQLHttpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {access_token}"); graphQLHttpClient.DefaultRequestHeaders.Add("x-authScheme", $"self-testserver"); var graphQLResponse = await graphQLHttpClient.GetAsync(graphQlRequest); graphQLResponse.ShouldNotBeNull(); } }
public async Task success_app_identity_bind_and_refresh_GET() { AppIdentityResultModel appIdentityResponse = null; using (var graphQLHttpClient = new GraphQL.Client.GraphQLClient(_graphQLClientOptions)) { var appIdentityCreate = new GraphQLRequest(@"query q($input: appIdentityCreate!) { appIdentityCreate(input: $input){ authority expires_in id_token } }") { OperationName = null, Variables = new { input = new { appId = "myApp 001", machineId = "machineId 001" } } }; var graphQLResponse = await graphQLHttpClient.GetAsync(appIdentityCreate); appIdentityResponse = (AppIdentityResultModel)graphQLResponse.GetDataFieldAs <AppIdentityResultModel>("appIdentityCreate"); //data->appIdentityCreate is casted as AppIdentityResponse appIdentityResponse.ShouldNotBeNull(); var handler = new JwtSecurityTokenHandler(); var tokenS = handler.ReadToken(appIdentityResponse.id_token) as JwtSecurityToken; tokenS.ShouldNotBeNull(); } /* * This next part fails because the validator calls out to authorities to get the public keys * The authority in the self case is under this TestServer and for some reason the discovery cache * cant reach this pretend http://localhost */ using (var graphQLHttpClient = new GraphQL.Client.GraphQLClient(_graphQLClientOptions)) { var appIdentityCreate = new GraphQLRequest(@"query q($input: appIdentityRefresh!) { appIdentityRefresh(input: $input){ authority expires_in id_token } }") { OperationName = null, Variables = new { input = new { id_token = appIdentityResponse.id_token } } }; var graphQLResponse = await graphQLHttpClient.GetAsync(appIdentityCreate); graphQLResponse.ShouldNotBeNull(); appIdentityResponse = graphQLResponse.GetDataFieldAs <AppIdentityResultModel>("appIdentityRefresh"); //data->appIdentityCreate is casted as AppIdentityResultModel appIdentityResponse.ShouldNotBeNull(); var handler = new JwtSecurityTokenHandler(); var tokenS = handler.ReadToken(appIdentityResponse.id_token) as JwtSecurityToken; tokenS.ShouldNotBeNull(); } }
/// <summary> /// Send an IntrospectionQuery via GET /// </summary> /// <param name="graphQLClient">The GraphQLClient</param> /// <param name="cancellationToken"></param> /// <returns>The GraphQLResponse</returns> public static Task <GraphQLResponse> GetIntrospectionQueryAsync(this GraphQLClient graphQLClient, CancellationToken cancellationToken = default) => graphQLClient.GetAsync(IntrospectionGraphQLRequest, cancellationToken);
/// <summary> /// Send an IntrospectionQuery via GET /// </summary> /// <param name="graphQLClient">The GraphQLClient</param> /// <param name="cancellationToken"></param> /// <returns>The GraphQLResponse</returns> public static async Task <GraphQLResponse> GetIntrospectionQueryAsync(this GraphQLClient graphQLClient, CancellationToken cancellationToken = default) => await graphQLClient.GetAsync(IntrospectionGraphQLRequest, cancellationToken).ConfigureAwait(false);