Permalink
Browse files

Fix some issues of last commit

  • Loading branch information...
1 parent 6c46b36 commit 90f4366f7d939d9593835c8410191cf1c1bb488c @mazen committed Oct 5, 2011
View
35 DependencyInjection/Security/Factory/OAuthFactory.php 100755 → 100644
@@ -16,8 +16,19 @@
*/
class OAuthFactory extends AbstractFactory
{
- protected $key;
+ /**
+ * The factory key. This is used by the security framework
+ * to check which factory to invoke.
+ *
+ * @var string
+ */
+ protected $key;
+ /**
+ * Client options
+ *
+ * @var array
+ */
protected $options = array(
'client_id' => null,
'client_secret' => null,
@@ -58,8 +69,8 @@ protected function createAuthProvider(ContainerBuilder $container, $id,
protected function createListener($container, $id, $config, $userProvider)
{
$providerType = $config['auth_provider'];
+ $id = $id.'.'.$providerType;
- $id = $id.'.'.$providerType;
$oAuthProvider = sprintf('etcpasswd_oauth.provider.%s', $providerType);
$listenerId = parent::createListener($container, $id, $config, $userProvider);
@@ -108,16 +119,16 @@ public function getKey()
return ($this->key !== null) ? $this->key : 'oauth';
}
- /**
- * Allows for overriding the provided key so that multiple instances of this factory can be generated
- * using different keys.
- *
- * @param string $key
- */
- public function setKey($key)
- {
- $this->key = $key;
- }
+ /**
+ * Allows for overriding the provided key so that multiple instances of this factory can be generated
+ * using different keys.
+ *
+ * @param string $key
+ */
+ public function setKey($key)
+ {
+ $this->key = $key;
+ }
/**
* {@inheritDoc}
View
5 Provider/FacebookProvider.php
@@ -12,7 +12,6 @@ class FacebookProvider extends Provider
public function createTokenResponse($clientId, $secret, $code, $redirectUrl = "")
{
-
$url = 'https://graph.facebook.com/oauth/access_token'
.'?client_id='.$clientId
.'&redirect_uri='.$redirectUrl
@@ -21,9 +20,7 @@ public function createTokenResponse($clientId, $secret, $code, $redirectUrl = ""
parse_str($this->request($url), $result);
- if(isset($result['error']))
- {
- // TODO:
+ if (isset($result['error'])) {
return;
}
View
9 Provider/GithubProvider.php 100755 → 100644
@@ -2,7 +2,6 @@
namespace Etcpasswd\OAuthBundle\Provider;
-
use Etcpasswd\OAuthBundle\Provider\TokenResponseInterface,
Etcpasswd\OAuthBundle\Provider\Token\GithubToken;
@@ -35,7 +34,6 @@ public function getAuthorizationUrl($clientId, $scope, $redirectUrl)
*/
public function createTokenResponse($clientId, $secret, $code, $redirectUrl = "")
{
-
$url = 'https://github.com/login/oauth/access_token'
.'?client_id='.$clientId
.'&redirect_url='.$redirectUrl
@@ -44,10 +42,8 @@ public function createTokenResponse($clientId, $secret, $code, $redirectUrl = ""
.'&grant_type=authorization_code';
$response = parse_str($this->request($url), $result);
-
-
- if(isset($result['error'])) {
+ if (isset($result['error'])) {
// @todo: handling of backend errors
// error
@@ -91,9 +87,8 @@ public function createTokenResponse($clientId, $secret, $code, $redirectUrl = ""
$url = 'https://api.github.com/user?access_token='.$accessToken;
$jsonObject = json_decode($this->request($url));
-
+
return new GithubToken($jsonObject, $result['access_token']);
}
-
}
View
8 Provider/GoogleProvider.php 100755 → 100644
@@ -31,29 +31,25 @@ public function createTokenResponse($clientId, $secret, $code, $redirectUrl = ""
$this->client->send($request, $response);
$data = json_decode($response->getContent());
- if(isset($data->error)) {
+ if (isset($data->error)) {
return;
}
$expiresAt = time()+$data->expires_in;
-
$people = 'https://www.googleapis.com/plus/v1/people/me'
@justinpfister
justinpfister added a line comment Jan 1, 2012

This line should be parameter driven -- for authorization purposes, it's probably better to use 'https://www.googleapis.com/oauth2/v1/userinfo' if you want the primary account email address. To limit access to email-only, you'll also need to set the scope should be ' https://www.googleapis.com/auth/userinfo.email' .. Another thing -- if you want to use "https://www.googleapis.com/plus/v1/people/me", you need to enable this API service via the Google API settings.

@gimler
gimler added a line comment Jan 9, 2012

+1

@justinpfister
justinpfister added a line comment Jan 9, 2012

I got yahoo working yesterday on my fork. It was tough because of all the double encoded hmacsha1 signatures and additional token requests. The code just needs a little cleaning up and needs a review with how it is itergrating with the config.yml For some reason, phpstorm isn't helping me cleanly update version control might have to do with my git settings... how ever its doing it is fine for me but it makes it tough for mazen if he wants to merge my updates.

@mazen
Owner
mazen added a line comment Jan 10, 2012

Can you provide a PR with that functionality?
I also dislike having to provide a hard coded end point for some google account data (and i was unaware they have an oauth2 userinfo api anyways)

@justinpfister
justinpfister added a line comment Jan 12, 2012

I submitted the pull request.. it's a simple if-statement. IF null (use the original default so we don't mess anyone up).. if the 'service' is set, then use the service defined in the security.yml. I learned that PhpStorm was 'Converting Line Spacing' and I found out how to disable it.. It has made for a nice Git learning experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
.'?key='.$clientId
- .'&access_token='.$data->access_token;
+ .'&access_token='.$data->access_token;
$request = new Request(Request::METHOD_GET, $people);
$response = new Response();
$this->client->send($request, $response);
$me = json_decode($response->getContent());
return new GoogleToken($me, $data->access_token, $expiresAt);
-
-
}
public function getAuthorizationUrl($clientId, $scope, $redirectUrl)
{
-
return 'https://accounts.google.com/o/oauth2/auth'
.'?client_id='.$clientId
.'&redirect_uri='.$redirectUrl
View
1 Provider/Provider.php 100755 → 100644
@@ -27,7 +27,6 @@ protected function request($url, $method = null)
$response = new Response();
$this->client->send($request, $response);
return $response->getContent();
-
}
}
View
0 Provider/Token/GoogleToken.php 100755 → 100644
File mode changed.
View
0 README.md 100755 → 100644
File mode changed.
View
34 Resources/config/security_factories.xml 100755 → 100644
@@ -13,25 +13,25 @@
</service>
<service id="etcpasswd_oauth.security.factory.facebook"
- class="%etcpasswd_oauth.security.factory.class%"
- public="false">
- <call method="setKey"><argument>oauth_facebook</argument></call>
- <tag name="security.listener.factory" />
- </service>
+ class="%etcpasswd_oauth.security.factory.class%"
+ public="false">
+ <call method="setKey"><argument>oauth_facebook</argument></call>
+ <tag name="security.listener.factory" />
+ </service>
- <service id="etcpasswd_oauth.security.factory.github"
- class="%etcpasswd_oauth.security.factory.class%"
- public="false">
- <call method="setKey"><argument>oauth_github</argument></call>
- <tag name="security.listener.factory" />
- </service>
+ <service id="etcpasswd_oauth.security.factory.github"
+ class="%etcpasswd_oauth.security.factory.class%"
+ public="false">
+ <call method="setKey"><argument>oauth_github</argument></call>
+ <tag name="security.listener.factory" />
+ </service>
- <service id="etcpasswd_oauth.security.factory.google"
- class="%etcpasswd_oauth.security.factory.class%"
- public="false">
- <call method="setKey"><argument>oauth_google</argument></call>
- <tag name="security.listener.factory" />
- </service>
+ <service id="etcpasswd_oauth.security.factory.google"
+ class="%etcpasswd_oauth.security.factory.class%"
+ public="false">
+ <call method="setKey"><argument>oauth_google</argument></call>
+ <tag name="security.listener.factory" />
+ </service>
</services>
</container>
View
2 Security/Core/Authentication/Provider/OAuthProvider.php 100755 → 100644
@@ -36,7 +36,7 @@ public function authenticate(TokenInterface $token)
{
$user = $this->userProvider->loadUserByUsername($token->getUsername());
- if($user) {
+ if ($user) {
$authenticatedToken = new OAuthtoken($user->getRoles(), $token->getResponse());
$authenticatedToken ->setAuthenticated(true);
$authenticatedToken ->setUser($user);
View
2 Security/Core/Authentication/Token/OAuthToken.php
@@ -36,6 +36,4 @@ public function getResponse()
return $this->response;
}
-
-
}
View
0 Security/Http/Firewall/OAuthListener.php 100755 → 100644
File mode changed.
View
1 Tests/Provider/GithubProviderTest.php
@@ -36,5 +36,4 @@ public function testAuthorizationUrlCreation()
);
}
-
}

0 comments on commit 90f4366

Please sign in to comment.