コード例 #1
0
        public async Task <ActionResult> Google([FromBody] OAuthLoginRequest model)
        {
            var payload = await GoogleJsonWebSignature.ValidateAsync(model.Token, new GoogleJsonWebSignature.ValidationSettings());

            var user = await _usersService.FindUserByEmailAsync(payload.Email);

            if (user == null)
            {
                bool emailConfirmed = true;
                user = await _usersService.CreateUserAsync(payload.Email, emailConfirmed);
            }

            var oAuth = new OAuth
            {
                OAuthId    = payload.Subject,
                Provider   = OAuthProvider.Google,
                GivenName  = payload.GivenName,
                FamilyName = payload.FamilyName,
                Name       = payload.Name,
                UserId     = user.Id,
                PictureUrl = payload.Picture
            };

            await _authService.CreateUpdateUserOAuthAsync(user.Id, oAuth);

            var roles = await _usersService.GetRolesAsync(user);

            var responseView = await _authService.CreateTokenAsync(RemoteIpAddress, user, oAuth, roles);

            return(Ok(responseView));
        }
コード例 #2
0
        /// <summary>
        /// Gets the URL used in the first step of the web flow. The Web application should redirect to this URL.
        /// </summary>
        /// <param name="request">Parameters to the Oauth web flow login url</param>
        /// <returns></returns>
        public Uri GetPipedriveLoginUrl(OAuthLoginRequest request)
        {
            Ensure.ArgumentNotNull(request, nameof(request));

            return(new Uri(hostAddress, ApiUrls.OAuthAuthorize())
                   .ApplyParameters(request.ToParametersDictionary()));
        }
コード例 #3
0
            public void ReturnsUrlWithAllParameters()
            {
                var request = new OAuthLoginRequest("secret")
                {
                    RedirectUri = new Uri("https://example.com/foo?foo=bar"),
                    State       = "canARY"
                };
                var connection = Substitute.For <IConnection>();

                connection.BaseAddress.Returns(new Uri("https://oauth.pipedrive.com"));
                var client = new OAuthClient(connection);

                var result = client.GetPipedriveLoginUrl(request);

                Assert.Equal("/oauth/authorize", result.AbsolutePath);
                Assert.Equal("?client_id=secret&redirect_uri=https%3A%2F%2Fexample.com%2Ffoo%3Ffoo%3Dbar&state=canARY", result.Query);
            }
コード例 #4
0
ファイル: AuthController.cs プロジェクト: stephengunter/blog
        public async Task <ActionResult> Login([FromBody] OAuthLoginRequest model)
        {
            var user = _usersService.FindUserByPhone(model.Token);

            if (user == null)
            {
                ModelState.AddModelError("auth", "登入失敗.");
                return(BadRequest(ModelState));
            }

            if (user.Email == _adminSettings.Email)
            {
                ModelState.AddModelError("auth", "登入失敗.");
                return(BadRequest(ModelState));
            }


            var roles = await _usersService.GetRolesAsync(user);

            var responseView = await _authService.CreateTokenAsync(RemoteIpAddress, user, roles);

            return(Ok(responseView));
        }