public static DocumentNode Deserialize(string json)
        {
            if (string.IsNullOrEmpty(json))
            {
                throw new ArgumentException(StitchingResources
                                            .IntrospectionDeserializer_Json_NullOrEmpty,
                                            nameof(json));
            }

            IntrospectionResult result = JsonConvert
                                         .DeserializeObject <IntrospectionResult>(json);

            var typeDefinitions = new List <IDefinitionNode>();

            typeDefinitions.Add(CreateSchema(result.Data.Schema));
            typeDefinitions.AddRange(CreateTypes(result.Data.Schema.Types));

            foreach (Directive directive in result.Data.Schema.Directives)
            {
                DirectiveDefinitionNode directiveDefinition =
                    CreateDirectiveDefinition(directive);
                if (directiveDefinition.Locations.Any())
                {
                    typeDefinitions.Add(directiveDefinition);
                }
            }

            return(new DocumentNode(typeDefinitions));
        }
Example #2
0
        private static async Task <SchemaFeatures> GetSchemaFeaturesAsync(
            HttpClient httpClient,
            HttpQueryClient queryClient)
        {
            var features = new SchemaFeatures();

            var request = new HttpQueryRequest
            {
                Query = GetIntrospectionQuery(_phase1)
            };

            string json = await queryClient.FetchStringAsync(
                request, httpClient)
                          .ConfigureAwait(false);

            IntrospectionResult result =
                JsonConvert.DeserializeObject <IntrospectionResult>(json);

            FullType directive = result.Data.Schema.Types.First(t =>
                                                                t.Name.Equals(_directiveName, StringComparison.Ordinal));

            features.HasRepeatableDirectives = directive.Fields.Any(t =>
                                                                    t.Name.Equals(_isRepeatable, StringComparison.Ordinal));
            features.HasDirectiveLocations = directive.Fields.Any(t =>
                                                                  t.Name.Equals(_locations, StringComparison.Ordinal));

            FullType schema = result.Data.Schema.Types.First(t =>
                                                             t.Name.Equals(_schemaName, StringComparison.Ordinal));

            features.HasSubscriptionSupport = schema.Fields.Any(t =>
                                                                t.Name.Equals(_subscriptionType, StringComparison.Ordinal));

            return(features);
        }
 public IntrospectionResultReturned(string id, string processId, IntrospectionResult parameter, int order)
 {
     Id        = id;
     ProcessId = processId;
     Parameter = parameter;
     Order     = order;
 }
        public string GetPayload(IntrospectionResult parameter)
        {
            if (parameter == null)
            {
                throw new ArgumentNullException(nameof(parameter));
            }

            var result = new Payload
            {
                Content = parameter
            };

            return(JsonConvert.SerializeObject(result));
        }
 public static SimpleIdServer.Dtos.Responses.IntrospectionResponse ToDto(this IntrospectionResult introspectionResult)
 {
     return(new SimpleIdServer.Dtos.Responses.IntrospectionResponse
     {
         Active = introspectionResult.Active,
         Audience = introspectionResult.Audience,
         ClientId = introspectionResult.ClientId,
         Expiration = introspectionResult.Expiration,
         IssuedAt = introspectionResult.IssuedAt,
         Issuer = introspectionResult.Issuer,
         Jti = introspectionResult.Jti,
         Nbf = introspectionResult.Nbf,
         Scope = introspectionResult.Scope.Split(' ').ToList(),
         Subject = introspectionResult.Subject,
         TokenType = introspectionResult.TokenType,
         UserName = introspectionResult.UserName
     });
 }
        public async Task <IntrospectionResult> Execute(
            IntrospectionParameter introspectionParameter,
            AuthenticationHeaderValue authenticationHeaderValue, string issuerName)
        {
            // 1. Validate the parameters
            if (introspectionParameter == null)
            {
                throw new ArgumentNullException(nameof(introspectionParameter));
            }

            if (string.IsNullOrWhiteSpace(introspectionParameter.Token))
            {
                throw new ArgumentNullException(nameof(introspectionParameter.Token));
            }

            _introspectionParameterValidator.Validate(introspectionParameter);

            // 2. Authenticate the client
            var instruction = CreateAuthenticateInstruction(introspectionParameter, authenticationHeaderValue);
            var authResult  = await _authenticateClient.AuthenticateAsync(instruction, issuerName);

            if (authResult.Client == null)
            {
                throw new IdentityServerException(ErrorCodes.InvalidClient, authResult.ErrorMessage);
            }

            // 3. Retrieve the token type hint
            var tokenTypeHint = Constants.StandardTokenTypeHintNames.AccessToken;

            if (Constants.AllStandardTokenTypeHintNames.Contains(introspectionParameter.TokenTypeHint))
            {
                tokenTypeHint = introspectionParameter.TokenTypeHint;
            }

            // 4. Trying to fetch the information about the access_token  || refresh_token
            GrantedToken grantedToken = null;

            if (tokenTypeHint == Constants.StandardTokenTypeHintNames.AccessToken)
            {
                grantedToken = await _tokenStore.GetAccessToken(introspectionParameter.Token);

                if (grantedToken == null)
                {
                    grantedToken = await _tokenStore.GetRefreshToken(introspectionParameter.Token);
                }
            }
            else
            {
                grantedToken = await _tokenStore.GetRefreshToken(introspectionParameter.Token);

                if (grantedToken == null)
                {
                    grantedToken = await _tokenStore.GetAccessToken(introspectionParameter.Token);
                }
            }

            // 5. Throw an exception if there's no granted token
            if (grantedToken == null)
            {
                throw new IdentityServerException(
                          ErrorCodes.InvalidToken,
                          ErrorDescriptions.TheTokenIsNotValid);
            }

            // 6. Fill-in parameters
            //// TODO : Specifiy the other parameters : NBF & JTI
            var result = new IntrospectionResult
            {
                Scope      = grantedToken.Scope,
                ClientId   = grantedToken.ClientId,
                Expiration = grantedToken.ExpiresIn,
                TokenType  = grantedToken.TokenType
            };

            // 7. Fill-in the other parameters
            if (grantedToken.IdTokenPayLoad != null)
            {
                var audiences    = string.Empty;
                var audiencesArr = grantedToken.IdTokenPayLoad.GetArrayClaim(StandardClaimNames.Audiences);
                var issuedAt     = grantedToken.IdTokenPayLoad.Iat;
                var issuer       = grantedToken.IdTokenPayLoad.Issuer;
                var subject      = grantedToken.IdTokenPayLoad.GetClaimValue(Jwt.Constants.StandardResourceOwnerClaimNames.Subject);
                var userName     = grantedToken.IdTokenPayLoad.GetClaimValue(Jwt.Constants.StandardResourceOwnerClaimNames.Name);
                if (audiencesArr.Any())
                {
                    audiences = string.Join(" ", audiencesArr);
                }

                result.Audience = audiences;
                result.IssuedAt = issuedAt;
                result.Issuer   = issuer;
                result.Subject  = subject;
                result.UserName = userName;
            }

            // 8. Based on the expiration date disable OR enable the introspection result
            var expirationDateTime = grantedToken.CreateDateTime.AddSeconds(grantedToken.ExpiresIn);
            var tokenIsExpired     = DateTime.UtcNow > expirationDateTime;

            if (tokenIsExpired)
            {
                result.Active = false;
            }
            else
            {
                result.Active = true;
            }

            return(result);
        }
Example #7
0
 /// <summary>
 ///     Create reader
 /// </summary>
 /// <param name="builder">Write types to builder</param>
 /// <param name="result">Introspection result to use as source</param>
 public IntrospectionSchemaReader(SchemaBuilder builder, IntrospectionResult result)
 {
     _builder = builder;
     _schema  = result.Schema;
 }