/* Decoded by unphp.net */ consumeAuthenticationTokenOrFail($uac, $tokenType, $token); $this->assertDuoStateMatchesAuthenticationTokenState($authToken, $duoState); return $authToken; } /** * Consume the duo callback authentication token or fail. * * @param \App\Utility\UserAccessControl $uac User access control * @param string $tokenType AuthenticationToken's token type * @param string $token AuthenticationToken's token * @return \App\Model\Entity\AuthenticationToken * @throws \Cake\Http\Exception\UnauthorizedException If the token could not be consumed */ private function consumeAuthenticationTokenOrFail( UserAccessControl $uac, string $tokenType, string $token ): AuthenticationToken { try { return (new AuthenticationTokenConsumeService())->consumeActiveNotExpiredOrFail( $token, $uac->getId(), $tokenType ); } catch (\Throwable $th) { $msg = __('The token should reference an active Duo callback authentication token.'); throw new UnauthorizedException($msg, null, $th); } } /** * Assert the Duo callback authentication token state value. * * @param \App\Model\Entity\AuthenticationToken $authToken The callback authentication token * @param string $duoState The Duo callback state * @return void * @throws \Cake\Http\Exception\InternalErrorException if the callback authentication token does not have state defined * @throws \Cake\Http\Exception\UnauthorizedException if the callback authentication token state value does not match the Duo callback state */ private function assertDuoStateMatchesAuthenticationTokenState( AuthenticationToken $authToken, string $duoState ): void { $authTokenState = $authToken->getDataValue('state'); if (empty($authTokenState)) { throw new InternalErrorException(__('An authentication token state is required.')); } if ($authTokenState !== $duoState) { throw new UnauthorizedException(__('The Duo state should match the authentication token state.')); } } } ?>