Пример #1
0
        public void CantGetAuthorizationTokenWithEmptyCode()
        {
            Exception exception =
                Assert.ThrowsAsync <NexaasIDException>(() => NexaasIdInstance.GetAuthorizationToken(string.Empty))
                .Result;

            Assert.Equal(exception.Message, Messages.EmptyCode);
        }
Пример #2
0
        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("~/"));
        }