Example #1
0
        public async Task RemoveTokenAsync(int userId, string audience, ILoginUow loginUow)
        {
            var applicationUserTokens = await loginUow.Repository <ApplicationUserToken>().FindByAsync(t => t.UserId == userId && t.AudienceType == audience);

            foreach (var applicationUserToken in applicationUserTokens)
            {
                await loginUow.RegisterDeletedAsync <ApplicationUserToken>(applicationUserToken);

                string token;
                this.Tokens.TryRemove(applicationUserToken.SecurityKey, out token);
            }
            await loginUow.CommitAsync();
        }
Example #2
0
        public async Task SaveTokenAsync(int userId, string audience, KeyValuePair <string, string> token, ILoginUow loginUow)
        {
            var applicationUserToken = new ApplicationUserToken
            {
                AudienceType    = audience,
                CreatedDateTime = DateTime.UtcNow,
                UserId          = userId,
                JwtToken        = token.Value,
                SecurityKey     = token.Key
            };
            await loginUow.RegisterNewAsync <ApplicationUserToken>(applicationUserToken);

            await loginUow.CommitAsync();

            this.Tokens.AddOrUpdate(token.Key, token.Value, (x, y) => token.Value);
        }