コード例 #1
0
        public async Task <bool> VerifyAsync(Guid tokenId, string code, CancellationToken ct)
        {
            var token = await _identityTokensService.GetAsync(tokenId, ct);

            if (token == null ||
                token.UseDateTime.HasValue ||
                token.ExpirationDateTime < DateTime.UtcNow ||
                token.Type != IdentityTokenType.PhoneValidation ||
                token.Value != code)
            {
                return(false);
            }

            await _identityTokensService.SetIsUsedAsync(tokenId, ct);

            await _identitiesService.VerifyAsync(new[] { token.IdentityId }, ct);

            return(true);
        }
コード例 #2
0
        public async Task <bool> IsTokenValidAsync(Guid tokenId, string code, CancellationToken ct)
        {
            var token = await _identityTokensService.GetAsync(tokenId, ct);

            return(IsValidToken(token, code));
        }
コード例 #3
0
        public async Task <ActionResult> Register([FromForm] PostRegisterRequest request, CancellationToken ct)
        {
            var client = await _ioAuthClientsService.GetByClientIdAsync(request.client_id, ct);

            if (!client.IsValid())
            {
                return(BadRequest("Client not found"));
            }

            if (!client.IsMatchRedirectUri(request))
            {
                return(BadRequest("Invalid redirect uri"));
            }

            if (!client.IsScopesInclude(request.scope))
            {
                return(BadRequest("Invalid scopes"));
            }

            if (request.Password != request.PasswordConfirmation)
            {
                var newRegisterRequest = new GetRegisterRequest
                {
                    client_id           = request.client_id,
                    response_type       = request.response_type,
                    scope               = request.scope,
                    state               = request.state,
                    redirect_uri        = request.redirect_uri,
                    Surname             = request.Surname,
                    Name                = request.Name,
                    Login               = request.Login,
                    Email               = request.Email,
                    Phone               = request.Phone,
                    IsPasswordsNotEqual = true
                };

                return(RedirectToAction("Register", newRegisterRequest));
            }

            var isLoginExists = await _identityStatusService.IsLoginExistsAsync(request.Login, ct);

            var isEmailExists = await _identityStatusService.IsEmailExistsAsync(request.Email, ct);

            var isPhoneExists = await _identityStatusService.IsPhoneExistsAsync(request.Phone, ct);

            if (isLoginExists || isEmailExists || isPhoneExists)
            {
                var newRegisterRequest = new GetRegisterRequest
                {
                    client_id     = request.client_id,
                    response_type = request.response_type,
                    scope         = request.scope,
                    state         = request.state,
                    redirect_uri  = request.redirect_uri,
                    Surname       = request.Surname,
                    Name          = request.Name,
                    Login         = request.Login,
                    Email         = request.Email,
                    Phone         = request.Phone,
                    IsLoginExists = isLoginExists,
                    IsEmailExists = isEmailExists,
                    IsPhoneExists = isPhoneExists
                };

                return(RedirectToAction("Register", newRegisterRequest));
            }

            var phoneIdentityTokenId = await _registrationService.RegisterAsync(
                request.Country,
                request.Surname,
                request.Name,
                request.Login,
                request.Email,
                request.Phone,
                request.Password,
                IpAddress,
                UserAgent,
                ct);

            var authorizeResponse = await _oauthService.AuthorizeAsync(
                request.Country,
                request.Login,
                request.Password,
                request.response_type,
                request.redirect_uri,
                request.state,
                IpAddress,
                UserAgent,
                request.scope.ToScopeList(),
                client.Audience,
                ct);

            if (authorizeResponse.IsInvalidCredentials)
            {
                var newAuthorizeRequest = new GetAuthorizeRequest
                {
                    client_id            = request.client_id,
                    response_type        = request.response_type,
                    scope                = request.scope,
                    state                = request.state,
                    redirect_uri         = request.redirect_uri,
                    IsInvalidCredentials = true
                };

                return(RedirectToAction("Authorize", newAuthorizeRequest));
            }

            var getVerifyPhoneRequest = new GetVerifyPhoneRequest
            {
                TokenId       = phoneIdentityTokenId,
                CallbackUri   = authorizeResponse.CallbackUri,
                IsInvalidCode = false
            };

            if (_webHostEnvironment.IsDevelopment())
            {
                var phoneIdentityToken = await _identityTokensService.GetAsync(phoneIdentityTokenId, ct);

                getVerifyPhoneRequest.Code = phoneIdentityToken?.Value;
            }

            return(RedirectToAction("VerifyPhone", getVerifyPhoneRequest));
        }