* @package taoLti */ class LtiAuthAdapter implements \common_user_auth_Adapter, ServiceLocatorAwareInterface { use ServiceLocatorAwareTrait; /** * * @var common_http_Request */ protected $request; /** * Creates an Authentication adapter from an OAuth Request * * @param common_http_Request $request */ public function __construct(common_http_Request $request) { $this->request = $request; } /** * (non-PHPdoc) * @see \common_user_auth_Adapter::authenticate() * * @return user\LtiUser * @throws LtiException * @throws LtiVariableMissingException * @throws \ResolverException * @throws \common_Exception * @throws \common_exception_Error * @throws \core_kernel_users_CacheException * @throws \core_kernel_users_Exception */ public function authenticate() { try { /** @var OauthService $oauthService */ $oauthService = $this->getServiceLocator()->get(OauthService::SERVICE_ID); $oauthService->validate($this->request); $ltiLaunchData = $this->getLaunchData(); /** @var LtiUserService $userService */ $userService = $this->getServiceLocator()->get(LtiUserService::SERVICE_ID); return $userService->findOrSpawnUser($ltiLaunchData); } catch (common_http_InvalidSignatureException $e) { throw new LtiException('Invalid LTI signature', LtiErrorMessage::ERROR_UNAUTHORIZED); } catch (LockOutException $e) { throw new LtiException('Too many incorrect attempts', LtiErrorMessage::ERROR_UNAUTHORIZED); } } /** * @return LtiLaunchData * @throws \ResolverException */ protected function getLaunchData() { return LtiLaunchData::fromRequest($this->request); } }