private function registerMicrosoftOAuth(Application $app)
 {
     $app['microsoft_oauth.access_token_provider.browser.client'] = $app->share(function () {
         return new Curl();
     });
     $app['microsoft_oauth.access_token_cache.cache'] = $app->share(function (Application $app) {
         return new ArrayCache();
     });
     $app['microsoft_oauth.access_token_cache'] = $app->share(function (Application $app) {
         return new AccessTokenCache($app['microsoft_oauth.access_token_cache.cache']);
     });
     $app['microsoft_oauth.access_token_provider.browser'] = $app->share(function (Application $app) {
         return new Browser($app['microsoft_oauth.access_token_provider.browser.client']);
     });
     $app['microsoft_oauth.access_token_provider'] = $app->share(function (Application $app) {
         if (!isset($app['microsoft_oauth.client_id'])) {
             throw new \InvalidArgumentException('Please provide your Microsoft OAuth client ID as option "microsoft_oauth.client_id"');
         }
         if (!isset($app['microsoft_oauth.client_secret'])) {
             throw new \InvalidArgumentException('Please provide your Microsoft OAuth client secret as option "microsoft_oauth.client_secret"');
         }
         $accessTokenProvider = new AccessTokenProvider($app['microsoft_oauth.access_token_provider.browser'], $app['microsoft_oauth.client_id'], $app['microsoft_oauth.client_secret']);
         $accessTokenProvider->setCache($app['microsoft_oauth.access_token_cache']);
         return $accessTokenProvider;
     });
 }
 protected function setUp()
 {
     $client = new Curl();
     $client->setTimeout(30);
     $this->browser = new Browser($client);
     $clientId = $this->getEnvironmentVariable('MICROSOFT_OAUTH_CLIENT_ID');
     $clientSecret = $this->getEnvironmentVariable('MICROSOFT_OAUTH_CLIENT_SECRET');
     $cache = new ArrayCache();
     $accessTokenCache = new AccessTokenCache($cache);
     $accessTokenProvider = new AccessTokenProvider($this->browser, $clientId, $clientSecret);
     $accessTokenProvider->setCache($accessTokenCache);
     $this->translator = new MicrosoftTranslator($this->browser, $accessTokenProvider);
 }
 public function testGetTokenWithCacheHit()
 {
     $scope = 'theScope';
     $grantType = 'theGrantType';
     $accessToken = 'accessToken';
     // the cache already contains an access token
     $accessTokenCache = $this->createMockAccessTokenCache();
     $accessTokenCache->expects($this->once())->method('has')->with($scope, $grantType)->will($this->returnValue(true));
     // the browser should not be used
     $browser = $this->createMockBrowser();
     $browser->expects($this->never())->method('post');
     // the access token will be retrieved from the cache
     $accessTokenCache->expects($this->once())->method('get')->with($scope, $grantType)->will($this->returnValue($accessToken));
     $accessTokenProvider = new AccessTokenProvider($browser, 'theClientId', 'theClientSecret');
     $accessTokenProvider->setCache($accessTokenCache);
     $accessTokenProvider->getAccessToken($scope, $grantType);
 }