当前位置: 首页>>代码示例>>C#>>正文


C# BsonDocument.GetValueOrDefault方法代码示例

本文整理汇总了C#中BsonDocument.GetValueOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# BsonDocument.GetValueOrDefault方法的具体用法?C# BsonDocument.GetValueOrDefault怎么用?C# BsonDocument.GetValueOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BsonDocument的用法示例。


在下文中一共展示了BsonDocument.GetValueOrDefault方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Deserialize

        public async Task<RefreshToken> Deserialize(BsonDocument doc)
        {
            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);
            return token;
        }
开发者ID:nielsmeijssen,项目名称:IdentityServer.v3.MongoDb,代码行数:14,代码来源:RefreshTokenSerializer.cs

示例2: Version1

 private static Scope Version1(BsonDocument doc)
 {
     var scope = new Scope
     {
         Name = doc["_id"].AsString,
         DisplayName = doc.GetValueOrDefault("displayName", Default.DisplayName),
         Claims = new List<ScopeClaim>(
             doc.GetValueOrDefault(
                 "claims",
                 claimDoc =>
                 {
                     var claim = new ScopeClaim();
                     claim.Name = claimDoc.GetValueOrDefault("name", claim.Name);
                     claim.AlwaysIncludeInIdToken = claimDoc.GetValueOrDefault("alwaysIncludeInIdToken",
                         claim.AlwaysIncludeInIdToken);
                     claim.Description = claimDoc.GetValueOrDefault("description", claim.Description);
                     return claim;
                 },
                 new ScopeClaim[] { }
                 )),
     };
     scope.ClaimsRule = doc.GetValueOrDefault("claimsRule", scope.ClaimsRule);
     scope.Description = doc.GetValueOrDefault("description", scope.Description);
     scope.Emphasize = doc.GetValueOrDefault("emphasize", scope.Emphasize);
     scope.Enabled = doc.GetValueOrDefault("enabled", scope.Enabled);
     scope.IncludeAllClaimsForUser = doc.GetValueOrDefault("includeAllClaimsForUser",
         scope.IncludeAllClaimsForUser);
     scope.Required = doc.GetValueOrDefault("required", scope.Required);
     scope.ShowInDiscoveryDocument = doc.GetValueOrDefault("showInDiscoveryDocument",
         scope.ShowInDiscoveryDocument);
     scope.Type = doc.GetValueOrDefault("type", scope.Type);
     return scope;
 }
开发者ID:nielsmeijssen,项目名称:IdentityServer.v3.MongoDb,代码行数:33,代码来源:ScopeSerializer.cs

示例3: Version1

 private static IEnumerable<Claim> Version1(BsonDocument doc)
 {
     return doc.GetValueOrDefault(
             "claims",
             c => new Claim(c["type"].AsString, c["value"].AsString),
             new Claim[] { }).ToList();
 }
开发者ID:nielsmeijssen,项目名称:IdentityServer.v3.MongoDb,代码行数:7,代码来源:ClaimSetSerializer.cs

示例4: Version1

        private static async Task<AuthorizationCode> Version1(
            BsonDocument doc, 
            IClientStore clientStore,
            IScopeStore scopeStore)
        {
            var code = new AuthorizationCode();
            code.CreationTime = doc.GetValueOrDefault("creationTime", code.CreationTime);
            code.IsOpenId = doc.GetValueOrDefault("isOpenId", code.IsOpenId);
            code.RedirectUri = doc.GetValueOrDefault("redirectUri", code.RedirectUri);
            code.WasConsentShown = doc.GetValueOrDefault("wasConsentShown", code.WasConsentShown);
            code.Nonce = doc.GetValueOrDefault("nonce", code.Nonce);
            var claimsPrincipal = new ClaimsPrincipal();
            IEnumerable<ClaimsIdentity> identities = doc.GetValueOrDefault("subject", sub =>
            {
                string authenticationType = sub.GetValueOrDefault("authenticationType", (string)null);
                var claims = sub.GetNestedValueOrDefault("claimSet", ClaimSetSerializer.Deserialize, new Claim[] { });
                ClaimsIdentity identity = authenticationType == null
                    ? new ClaimsIdentity(claims)
                    : new ClaimsIdentity(claims, authenticationType);
                return identity;
            }, new ClaimsIdentity[] { });
            claimsPrincipal.AddIdentities(identities);
            code.Subject = claimsPrincipal;

            var clientId = doc["_clientId"].AsString;
            code.Client = await clientStore.FindClientByIdAsync(clientId);
            if (code.Client == null)
            {
                throw new InvalidOperationException("Client not found when deserializing authorization code. Client id: " + clientId); 
            }

            var scopes = doc.GetValueOrDefault(
                "requestedScopes",
                (IEnumerable<string>)new string[] { }).ToArray();
            code.RequestedScopes = await scopeStore.FindScopesAsync(scopes);
            if (scopes.Count() > code.RequestedScopes.Count())
            {
                throw new InvalidOperationException("Scopes not found when deserializing authorization code. Scopes: " + string.Join(", ",scopes.Except(code.RequestedScopes.Select(x=>x.Name)))); 
            }
            return code;
        }
开发者ID:nielsmeijssen,项目名称:IdentityServer.v3.MongoDb,代码行数:41,代码来源:AuthorizationCodeSerializer.cs


注:本文中的BsonDocument.GetValueOrDefault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。