コード例 #1
0
        public async Task <Claim[]> GetClaimsAsync(string globalId, string name, string url)
        {
            List <Claim> claims  = new List <Claim>();
            var          profile = await GetProfileAsync(globalId, name, url) as Dictionary <string, string>;

            if (profile != null)
            {
                foreach (string prop in profile.Keys)
                {
                    if (profile[prop].HasValue())
                    {
                        claims.Add(new Claim(prop, profile[prop]));
                    }
                }
            }

            // add role claim
            var account = await _store.LoadByGuid(globalId);

            claims.Add(new Claim(ClaimTypes.Role, account.Role.ToString().ToLower()));

            return(claims.ToArray());
        }
コード例 #2
0
ファイル: AccountService.cs プロジェクト: cmu-sei/Identity
        public async Task <Account> RegisterExternalUser(ClaimsPrincipal principal, string location)
        {
            // add account & properties
            string updated_at = principal.FindFirst(ClaimTypes.UpdatedAt)?.Value;

            if (!DateTime.TryParse(updated_at, out DateTime lastUpdate))
            {
                lastUpdate = DateTime.MinValue;
            }

            var subClaim = principal.FindFirst(ClaimTypes.Subject);
            var account  = await _store.LoadByGuid(subClaim.Value);

            if (account == null)
            {
                account = new Data.Account {
                    GlobalId    = subClaim.Value,
                    WhenCreated = DateTime.UtcNow,
                    UpdatedAt   = lastUpdate
                };

                await _store.Add(account);

                await SetAccountNames(account, principal.FindFirst(ClaimTypes.Name)?.Value ?? "anonymous", false);

                UpdateProperty(account, "origin", subClaim.Issuer);
                UpdateExternalUserProfile(account, principal);
            }
            else
            {
                // sync props
                if (lastUpdate.CompareTo(account.UpdatedAt) > 0)
                {
                    UpdateExternalUserProfile(account, principal);
                    account.UpdatedAt = lastUpdate;
                }
            }
            return(await CompleteAuthentication(account, location));
        }