public function authenticate(ExchangeIdSiteTokenRequest $exchangeIdSiteTokenRequest) { $attempt = new ExchangeIdSiteTokenAttempt(); $attempt->setGrantType($exchangeIdSiteTokenRequest->getGrantType())->setToken($exchangeIdSiteTokenRequest->getToken()); $grantResult = $this->application->dataStore->create($this->application->getHref() . self::OAUTH_TOKEN_PATH, $attempt, \Stormpath\Stormpath::GRANT_AUTHENTICATION_TOKEN); $builder = new OauthGrantAuthenticationResultBuilder($grantResult); return $builder->build(); }
public function verify($jwt = null) { // JWT was not passed in if (!$jwt) { $jwt = $this->retrieveJwtFromHeader(); } // JWT was not in header if (!$jwt) { $jwt = $this->retrieveJwtFromCookie(); } // JWT not in Header or Cookie if (!$jwt) { throw new \InvalidArgumentException('Could not find access token, please pass in JWT'); } if ($this->localValidation) { return JWT::decode($jwt, $this->application->dataStore->getApiKey()->getSecret(), ['HS256']); } $href = $this->application->getHref() . '/authTokens/' . $jwt; return $this->application->dataStore->getResource($href, Stormpath::ACCESS_TOKEN); }
public function testFacebookProviderAccount() { $requestExecutor = $this->getMock('\\Stormpath\\Http\\RequestExecutor'); $apiKey = $this->getMock('\\Stormpath\\ApiKey', array(), array("mockId", "mockSecret")); $cacheManager = $this->getMock('\\Stormpath\\Cache\\CacheManager'); $dataStore = $this->getMock('\\Stormpath\\DataStore\\DefaultDataStore', array('create'), array($requestExecutor, $apiKey, $cacheManager)); $accessToken = "4/XrsKzIJuy3ye57eqbanlQDN1wZHYfaUV-MFyC6dRjRw.wnCoOEKwnlwXXmXvfARQvthKMCbPmgI"; $providerAccountRequest = new \Stormpath\Provider\FacebookProviderAccountRequest(array("accessToken" => $accessToken)); $providerData = $providerAccountRequest->getProviderData($dataStore); $this->assertEquals(FacebookProvider::FACEBOOK_PROVIDER_ID, $providerData->providerId); $this->assertEquals($accessToken, $providerData->accessToken); $providerAccountAccess = $dataStore->instantiate(Stormpath::PROVIDER_ACCOUNT_ACCESS); $providerAccountAccess->providerData = $providerData; $application = new Application($dataStore); $providerAccountResult = $this->getMock('\\Stormpath\\Resource\\ProviderAccountResult'); $dataStore->expects($this->once())->method('create')->with($this->equalTo($application->getHref() . '/' . Account::PATH), $this->equalTo($providerAccountAccess), $this->equalTo(Stormpath::PROVIDER_ACCOUNT_RESULT))->will($this->returnValue($providerAccountResult)); $returnedResult = $application->getAccount($providerAccountRequest); $this->assertEquals($providerAccountResult, $returnedResult); }