コード例 #1
0
        public Token Deserialize(BsonDocument doc)
        {
            var token = new Token();

            token.Audience     = doc.GetValueOrDefault("audience", token.Audience);
            token.Claims       = new List <Claim>(doc.GetNestedValueOrDefault("claims", _claimsSetSerializer.Deserialize, new List <Claim>()));
            token.Client       = doc.GetNestedValueOrDefault("client", _clientSerializer.Deserialize, token.Client);
            token.CreationTime = doc.GetValueOrDefault("creationTime", token.CreationTime);
            token.Issuer       = doc.GetValueOrDefault("issuer", token.Issuer);
            token.Lifetime     = doc.GetValueOrDefault("lifetime", token.Lifetime);
            token.Type         = doc.GetValueOrDefault("type", token.Type);
            return(token);
        }
コード例 #2
0
        public RefreshToken Deserialize(BsonDocument doc)
        {
            var token = new RefreshToken();

            token.AccessToken = doc.GetNestedValueOrDefault(
                "accessToken",
                _tokenSerializer.Deserialize,
                token.AccessToken);

            token.ClientId     = doc.GetValueOrDefault("clientId", token.ClientId);
            token.CreationTime = doc.GetValueOrDefault("creationTime", token.CreationTime);
            token.LifeTime     = doc.GetValueOrDefault("lifetime", token.LifeTime);
            return(token);
        }
コード例 #3
0
        static async Task <RefreshToken> Version2(BsonDocument doc, TokenSerializer tokenSerializer, ClaimSetSerializer claimsSerializer)
        {
            var       token = new RefreshToken();
            BsonValue at;

            if (doc.TryGetValue("accessToken", out at))
            {
                token.AccessToken = await tokenSerializer.Deserialize(at.AsBsonDocument);
            }
            token.CreationTime = doc.GetValueOrDefault("creationTime", token.CreationTime);
            token.LifeTime     = doc.GetValueOrDefault("lifetime", token.LifeTime);
            token.Version      = doc.GetValueOrDefault("version", token.Version);
            var claims = doc.GetNestedValueOrDefault("subjectClaims", claimsSerializer.Deserialize, new Claim[] {});

            token.Subject = new ClaimsPrincipal(new ClaimsIdentity(claims));
            return(token);
        }
コード例 #4
0
        private static Client Version2(BsonDocument doc)
        {
            var client = Unchanged(doc);

            //CHANGE
            client.AllowedScopes.AddRange(doc.GetValueOrDefault("allowedScopes", EmptyStringSet));
            //CHANGE
            client.AllowedCustomGrantTypes.AddRange(doc.GetValueOrDefault("allowedCustomGrantTypes", EmptyStringSet));
            client.AllowAccessToAllScopes = doc.GetValueOrDefault("allowAccessToAllScopes",
                                                                  client.AllowAccessToAllScopes);
            client.AllowAccessToAllCustomGrantTypes = doc.GetValueOrDefault("allowAccessToAllCustomGrantTypes",
                                                                            client.AllowAccessToAllCustomGrantTypes);

            client.Claims.AddRange(doc.GetNestedValueOrDefault("clientClaims", ClaimSetSerializer.Deserialize,
                                                               new Claim[] {}));
            return(client);
        }
コード例 #5
0
        private static async Task <Token> Version1(BsonDocument doc, IClientStore clientStore)
        {
            var token = new Token();

            token.Audience = doc.GetValueOrDefault("audience", token.Audience);
            token.Claims   = new List <Claim>(doc.GetNestedValueOrDefault("claims", ClaimsSetSerializer.Deserialize, new List <Claim>()));
            var clientId = doc.GetValueOrDefault("client", (string)null);
            var client   = await clientStore.FindClientByIdAsync(clientId);

            if (client == null)
            {
                throw new InvalidOperationException("Client not found when deserializing token. Client id: " + clientId);
            }
            token.Client       = client;
            token.CreationTime = doc.GetValueOrDefault("creationTime", token.CreationTime);
            token.Issuer       = doc.GetValueOrDefault("issuer", token.Issuer);
            token.Lifetime     = doc.GetValueOrDefault("lifetime", token.Lifetime);
            token.Type         = doc.GetValueOrDefault("type", token.Type);
            token.Version      = doc.GetValueOrDefault("version", token.Version);
            return(token);
        }