Ejemplo n.º 1
0
        /// <summary>
        ///     Handle the request to authorize the request
        /// </summary>
        /// <param name="request">The request to handle</param>
        /// <param name="jsonRequest">The parameters of the call, if JSON request</param>
        public DnoaAuthZResponse HandleTokenRequest(IRequest request, CreateAccessToken jsonRequest)
        {
            OutgoingWebResponse response = GetResponse(request, jsonRequest);

            var responseBody = response.Body.FromJson <Dictionary <string, string> >();

            if (response.Status == HttpStatusCode.OK)
            {
                return(new DnoaAuthZResponse
                {
                    AccessToken = responseBody[@"access_token"],
                    RefreshToken = responseBody[@"refresh_token"],
                    ExpiresIn = responseBody[@"expires_in"],
                    TokenType = responseBody[@"token_type"],
                    Scope = responseBody[@"scope"],
                });
            }

            string error   = (responseBody.ContainsKey(@"error")) ? responseBody[@"error"] : string.Empty;
            string message = (responseBody.ContainsKey(@"error_description"))
                ? responseBody[@"error_description"]
                : error;

            throw LogicErrorThrower.RuleViolation(message);
        }
Ejemplo n.º 2
0
        internal IUserAccount UpdateUserAccount(string currentUsername, string id, string oldPasswordHash,
                                                string newPasswordHash,
                                                string forename, string surname, string email, string mobilePhone, Address address)
        {
            Guard.NotNull(() => currentUsername, currentUsername);
            Guard.NotNull(() => id, id);

            // Get the account
            IUserAccount accountToUpdate = Storage.Get(id);

            if (accountToUpdate == null)
            {
                throw LogicErrorThrower.ResourceNotFound();
            }
            accountToUpdate.Address = accountToUpdate.Address ?? new Address();

            //Verify password hashes
            if (newPasswordHash.HasValue())
            {
                if (!accountToUpdate.PasswordHash.EqualsOrdinal(oldPasswordHash))
                {
                    throw LogicErrorThrower.RuleViolation(Resources.UserAccountsManager_PasswordsDontMatch);
                }

                accountToUpdate.PasswordHash = newPasswordHash;
            }

            //Update (allowable) account properties
            accountToUpdate.Forenames   = forename;
            accountToUpdate.Surname     = surname;
            accountToUpdate.Email       = email;
            accountToUpdate.MobilePhone = mobilePhone;
            if (address != null)
            {
                accountToUpdate.Address.PopulateWithNonDefaultValues(address);
            }

            IUserAccount newAccount = Storage.Update(id, accountToUpdate);

            // TODO: Audit the update of the account

            return(newAccount);
        }