Beispiel #1
0
 public UserAuthenticationDTO(UserAuthenticationId id, UserId userid, CredentialType credentialtype, string secret, string displayname, DateTime creationtime, bool isrevoked = false, DateTime?revoketime = null)
 {
     Id             = id;
     UserId         = userid;
     CredentialType = credentialtype;
     Secret         = secret;
     DisplayName    = displayname;
     CreationTime   = creationtime;
     IsRevoked      = isrevoked;
     RevokeTime     = revoketime;
 }
Beispiel #2
0
        public async Task <UserAuthenticationDTO> GetAsync(UserAuthenticationId id)
        {
            var sqlParams = new
            {
                Id = id.RawValue
            };
            string sql = @";
                SELECT Id,
                       UserId,
                       CredentialType,
                       Secret,
                       DisplayName,
                       CreationTime,
                       IsRevoked,
                       RevokeTime
                FROM dbo.UserAuthenticationMethods 
                WHERE Id = @Id;
            ";

            return(await _db.QuerySingleOrDefault(async (db) =>
            {
                return await db.FetchAsync <UserAuthenticationDTO>(sql, sqlParams);
            }));
        }
Beispiel #3
0
 private void AddUserAuthClaim(ClaimsIdentity identity, UserAuthenticationId userAuthId)
 {
     identity.AddClaim(new Claim("userAuthId", userAuthId.RawValue.ToString()));
 }
Beispiel #4
0
        public async Task <RevocationDetails> RevokeAuthenticationAsync(UserId userId, UserAuthenticationId id)
        {
            var userAuth = await _persistence.UserAuthentications.GetAsync(id);

            if (!userAuth.UserId.Equals(userId))
            {
                return(RevocationDetails.GetFailed("Could not find specified account details"));
            }

            if (userAuth.IsRevoked)
            {
                return(RevocationDetails.GetFailed("Linked account has already been revoked"));
            }

            userAuth.IsRevoked  = true;
            userAuth.RevokeTime = DateTime.UtcNow;
            await _persistence.UserAuthentications.UpdateAsync(userAuth);

            return(RevocationDetails.GetSuccess());
        }