public async Task <IActionResult> Signin(string code)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                Redirect(_nexaasId.GetAuthorizeUrl());
            }

            ///Retrive user access token
            BaseResponse <OauthTokenResponse> authTokenResponse = await _nexaasId.GetAuthorizationToken(code);

            ///Retrive user data
            BaseResponse <Profile> profileResponse = await _nexaasId.GetProfile(authTokenResponse.Data);

            Profile profile = profileResponse.Data;

            ///Define user claims
            var claims = new []
            {
                new Claim(ClaimTypes.Name, profile.FullName),
                new Claim(ClaimTypes.Email, profile.Email),
                new Claim("NexaasIDAccessToken", authTokenResponse.Data.AccessToken),
            };

            var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);

            ///Authenticates user
            await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
                                          new ClaimsPrincipal(claimsIdentity));

            return(Redirect("~/"));
        }
Exemple #2
0
        public async Task <IActionResult> ProfileInfo([FromServices] NexaasID nexaasId)
        {
            var accessToken = User.FindFirstValue("NexaasIDAccessToken");

            if (string.IsNullOrWhiteSpace(accessToken))
            {
                return(await Task.FromResult <IActionResult>(Redirect("~/auth")));
            }

            var profileResponse = await nexaasId.GetProfile(accessToken);

            if (profileResponse.StatusCode != HttpStatusCode.OK)
            {
                return(View());
            }

            profileResponse.Data.Emails = (await nexaasId.GetEmails(accessToken))?.Data;

            profileResponse.Data.ProfessionalInfo = (await nexaasId.GetProfessionalInfo(accessToken))?.Data;

            profileResponse.Data.Contacts = (await nexaasId.GetContacts(accessToken))?.Data;

            return(View(profileResponse.Data));
        }