Пример #1
0
        private async Task OnTokenValidated(TokenValidatedContext context)
        {
            if (context.SecurityToken is JwtSecurityToken token && context.Ticket.Principal.Identity is ClaimsIdentity identity)
            {
                identity.AddClaim(new Claim("access_token", token.RawData));
                var settings = new AppSettings {
                    DB_Connection = Environment.GetEnvironmentVariable("APP_DB_CONNECTION") ?? Configuration["App:DB_Connection"]
                };
                var db = new MySqlDatabase(settings);
                var memberDatasource = new MemberDatasource(db);
                var userid           = identity.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
                var member           = memberDatasource.Get(userid) ?? new Member();
                if (!member.UpdatedDate.HasValue || member.UpdatedDate.Value.AddDays(7) < DateTime.Now)
                {
                    var authInfo = await GetUserInfo(token.RawData);

                    member.Map(authInfo);

                    if (member.MemberID < 1)
                    {
                        member.MemberID = memberDatasource.Insert(member);
                    }
                    else
                    {
                        memberDatasource.Update(member);
                    }
                }

                identity.AddClaim(new Claim(nameof(member.MemberID), member.MemberID.ToString()));
            }
        }
 private void WhenGetMember()
 {
     ThenMember = _datasource.Get(_someID);
 }