public async Task <IActionResult> AuthInfoAsync()
        {
            var idpClient        = _httpClientFactory.CreateClient(Constants.APIClientNames.IDPClient);
            var metaDataResponse = await idpClient.GetDiscoveryDocumentAsync();

            if (metaDataResponse.IsError)
            {
                throw new ApplicationException("Problem accessing the discovery endpoint.", metaDataResponse.Exception);
            }
            var idToken = await HttpContext.GetTokenAsync(OpenIdConnectParameterNames.IdToken);

            //get access token

            var accessToken = await HttpContext.GetTokenAsync(OpenIdConnectParameterNames.AccessToken);

            //call user info end point
            var userInfo = await idpClient.GetUserInfoAsync(new UserInfoRequest { Address = metaDataResponse.UserInfoEndpoint, Token = accessToken });

            if (userInfo.IsError)
            {
                throw new ApplicationException("Problem accessing the user info endpoint.", userInfo.Exception);
            }

            var model = new AuthInfoViewModel();

            model.IdToken    = idToken;
            model.AccesToken = accessToken;
            model.Email      = userInfo.Claims.FirstOrDefault(u => u.Type == "email")?.Value;
            model.Role       = userInfo.Claims.FirstOrDefault(u => u.Type == "role")?.Value;
            model.Operations = userInfo.Claims.FirstOrDefault(u => u.Type == "operations")?.Value;
            return(View("AuthInfo", model));
        }
예제 #2
0
        public async Task <IActionResult> AuthInfo()
        {
            var authInfoModel = new AuthInfoViewModel
            {
                AccessToken = BuildTokenViewModel(await HttpContext.GetTokenAsync(OpenIdConnectParameterNames.AccessToken)),
                IdToken     = BuildTokenViewModel(await HttpContext.GetTokenAsync(OpenIdConnectParameterNames.IdToken)),
            };

            return(View(authInfoModel));
        }
 public ActionResult <AuthInfoViewModel> Login(AuthInfoViewModel usuario) =>
 _loginService.Login(usuario.CPF, usuario.Matricula);