コード例 #1
0
        public async Task <IActionResult> OnGet()
        {
            System.Diagnostics.Debug.WriteLine($"\n_Host OnGet IsAuth? {User.Identity.IsAuthenticated}");

            if (User.Identity.IsAuthenticated)
            {
                var sid = User.Claims
                          .Where(c => c.Type.Equals("sid"))
                          .Select(c => c.Value)
                          .FirstOrDefault();

                System.Diagnostics.Debug.WriteLine($"sid: {sid}");

                if (sid != null && !Cache.HasSubjectId(sid))
                {
                    var authResult = await HttpContext.AuthenticateAsync("oidc");

                    DateTimeOffset expiration  = authResult.Properties.ExpiresUtc.Value;
                    string         accessToken = await HttpContext.GetTokenAsync("access_token");

                    string refreshToken = await HttpContext.GetTokenAsync("refresh_token");

                    Cache.Add(sid, expiration, accessToken, refreshToken);
                }
            }
            return(Page());
        }
コード例 #2
0
        public async Task <IActionResult> OnGet()
        {
            if (User.Identity.IsAuthenticated)
            {
                var sid = User.Claims.Where(c => c.Type.Equals("sid")).Select(c => c.Value).FirstOrDefault();

                if (sid != null && !_cache.HasSubjectId(sid))
                {
                    var authResult = await HttpContext.AuthenticateAsync(OpenIdConnectDefaults.AuthenticationScheme);

                    var expiration  = authResult.Properties.ExpiresUtc.Value;
                    var accessToken = await HttpContext.GetTokenAsync("access_token");

                    var refreshToken = await HttpContext.GetTokenAsync("refresh_token");

                    _cache.Add(sid, expiration, accessToken, refreshToken);
                }
            }
            return(Page());
        }