Пример #1
0
        public async Task <IActionResult> Edit(string appid)
        {
            Application app = _mapper.Map <Application>(await _applicationProcessor.GetApplicationById(appid));

            if (app == null)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                var authorizationResult = await _authorizationService.AuthorizeAsync(User, app, "ApplicationPolicy");

                if (authorizationResult.Succeeded)
                {
                    ApplicationFormModel viewModel = new ApplicationFormModel
                    {
                        Name        = app.Name,
                        RedirectUri = app.RedirectUri
                    };

                    return(View(viewModel));
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
        }
Пример #2
0
        /* POST https://api.authorization-server.com/token
         *  grant_type=password&
         *  username=USERNAME&
         *  password=PASSWORD&
         *  client_id=CLIENT_ID */
        public async Task <IActionResult> Post(PasswordTokenRequest request)
        {
            Application app = _mapper.Map <Application>(await _applicationProcessor.GetApplicationById(request.client_id));

            if (app != null)
            {
                if (app.Role == ApplicationRoles.FirstParty)
                {
                    if (await _userProcessor.UserExists(request.username))
                    {
                        if (await _userProcessor.Authenticate(request.username, request.password))
                        {
                            Connection connection = new Connection
                            {
                                User        = _mapper.Map <User>(await _userProcessor.GetUserByUsername(request.username)),
                                Application = app
                            };

                            connection = _mapper.Map <Connection>(await _connectionProcessor.CreateConnection(_mapper.Map <DataAccessLibrary.Models.Connection>(connection)));

                            return(Token(connection));
                        }
                    }
                }
            }

            return(Forbid());
        }