function it_should_create_new_user_when_none_was_found($userManager, $oauthRepository, UserInterface $user, UserResponseInterface $response, ResourceOwnerInterface $resourceOwner, UserOAuthInterface $oauth) { $resourceOwner->getName()->willReturn('google'); $response->getEmail()->willReturn(null); $response->getUsername()->willReturn('username'); $response->getNickname()->willReturn('user'); $response->getResourceOwner()->willReturn($resourceOwner); $response->getAccessToken()->willReturn('access_token'); $oauthRepository->findOneBy(array('provider' => 'google', 'identifier' => 'username'))->willReturn(null); $oauthRepository->createNew()->willReturn($oauth); $userManager->createUser()->willReturn($user); $oauth->setIdentifier('username'); $oauth->setProvider('google'); $oauth->setAccessToken('access_token'); $user->getUsername()->willReturn(null); $user->setUsername('user')->shouldBeCalled(); $user->setPlainPassword('2ff2dfe363')->shouldBeCalled(); $user->setEnabled(true)->shouldBeCalled(); $user->addOAuthAccount($oauth)->shouldBeCalled(); $userManager->updateUser($user)->shouldBeCalled(); $this->loadUserByOAuthUserResponse($response)->shouldReturn($user); }
/** * @param Request $request * @param ResourceOwnerInterface $resourceOwner * * @return string */ public function getServiceAuthUrl(Request $request, ResourceOwnerInterface $resourceOwner) { if ($resourceOwner->getOption('auth_with_one_url')) { $redirectUrl = $this->httpUtils->generateUri($request, $this->ownerMap->getResourceOwnerCheckPath($resourceOwner->getName())) . '?authenticated=true'; } else { $request->attributes->set('service', $resourceOwner->getName()); $redirectUrl = $this->httpUtils->generateUri($request, 'hwi_oauth_connect_service'); } return $redirectUrl; }
function it_should_create_new_user_when_none_was_found($userManager, FactoryInterface $customerFactory, FactoryInterface $userFactory, FactoryInterface $oauthFactory, RepositoryInterface $oauthRepository, CustomerInterface $customer, ShopUserInterface $user, UserResponseInterface $response, ResourceOwnerInterface $resourceOwner, UserOAuthInterface $oauth) { $resourceOwner->getName()->willReturn('google'); $response->getEmail()->willReturn(null); $response->getUsername()->willReturn('username'); $response->getNickname()->willReturn('user'); $response->getRealName()->willReturn('Name'); $response->getResourceOwner()->willReturn($resourceOwner); $response->getAccessToken()->willReturn('access_token'); $response->getRefreshToken()->willReturn('refresh_token'); $oauthRepository->findOneBy(['provider' => 'google', 'identifier' => 'username'])->willReturn(null); $oauthFactory->createNew()->willReturn($oauth); $userFactory->createNew()->willReturn($user); $customerFactory->createNew()->willReturn($customer); $customer->setFirstName('Name')->shouldBeCalled(); $oauth->setIdentifier('username'); $oauth->setProvider('google'); $oauth->setAccessToken('access_token'); $oauth->setRefreshToken('refresh_token'); $user->setCustomer($customer)->shouldBeCalled(); $user->getUsername()->willReturn(null); $user->setUsername('user')->shouldBeCalled(); $user->setPlainPassword('2ff2dfe363')->shouldBeCalled(); $user->setEnabled(true)->shouldBeCalled(); $user->addOAuthAccount($oauth)->shouldBeCalled(); $userManager->persist($user)->shouldBeCalled(); $userManager->flush()->shouldBeCalled(); $this->loadUserByOAuthUserResponse($response)->shouldReturn($user); }
/** * @param Request $request * @param ResourceOwnerInterface $resourceOwner * * @return string */ public function getServiceAuthUrl(Request $request, ResourceOwnerInterface $resourceOwner) { if ($resourceOwner->getOption('auth_with_one_url')) { return $this->httpUtils->generateUri($request, $this->getResourceOwnerCheckPath($resourceOwner->getName())); } $request->attributes->set('service', $resourceOwner->getName()); return $this->httpUtils->generateUri($request, 'hwi_oauth_connect_service'); }
/** * Key to for fetching or saving a token. * * @param ResourceOwnerInterface $resourceOwner * @param mixed $tokenId * * @return string */ protected function generateKey(ResourceOwnerInterface $resourceOwner, $tokenId) { return implode('.', array('_hwi_oauth.request_token', $resourceOwner->getName(), $resourceOwner->getOption('client_id'), $tokenId)); }
/** * Key to for fetching or saving a token. * * @param ResourceOwnerInterface $resourceOwner * @param string $key * @param string $type * * @return string */ protected function generateKey(ResourceOwnerInterface $resourceOwner, $key, $type) { return sprintf('_hwi_oauth.%s.%s.%s.%s', $resourceOwner->getName(), $resourceOwner->getOption('client_id'), $type, $key); }