Ver Fonte

correcciones

Luciano Andrade há 7 anos atrás
pai
commit
a03727651f

+ 1 - 1
OAuth/Response/PathUserResponse.php

@@ -26,7 +26,7 @@ class PathUserResponse extends \HWI\Bundle\OAuthBundle\OAuth\Response\PathUserRe
      */
     public function getRoles()
     {
-        return $this->getValueForPath('roles');
+        return (array)$this->getValueForPath('roles');
     }
 
     /**

+ 8 - 3
Security/OAuthProxyAuthenticator.php

@@ -16,10 +16,10 @@ use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerI
 use Buzz\Listener\BasicAuthListener;
 use Buzz\Message;
 
-use Symfony\Component\HttpFoundation\Session\Session;
-
 use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface;
 
+use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
+
 class OAuthProxyAuthenticator implements SimplePreAuthenticatorInterface, AuthenticationFailureHandlerInterface
 {
     public function __construct($client_id, $client_secret, $access_token_url, $user_info_url)
@@ -32,7 +32,10 @@ class OAuthProxyAuthenticator implements SimplePreAuthenticatorInterface, Authen
 
     public function createToken(Request $request, $providerKey)
     {
-        return new PreAuthenticatedToken($request->headers->get("php-auth-user"), $request->headers->get("php-auth-pw"), $providerKey);
+	if($request->headers->has("php-auth-user") and $request->headers->has("php-auth-pw"))
+		return new PreAuthenticatedToken($request->headers->get("php-auth-user"), $request->headers->get("php-auth-pw"), $providerKey);
+	return new AnonymousToken("anon.", "anon.");
+
     }
 
     public function supportsToken(TokenInterface $token, $providerKey)
@@ -102,6 +105,8 @@ class OAuthProxyAuthenticator implements SimplePreAuthenticatorInterface, Authen
 		$token["user_info"] = $auth_info;
 
 		file_put_contents("/tmp/.".base64_encode($username. ":" . $password), json_encode($token));
+	}else{
+		$auth_info = $token["user_info"];
 	}
 
 	$user = $userProvider->loadUserByUsername($auth_info["username"]);

+ 0 - 44
Security/OAuthProxyUserProvider.php

@@ -1,44 +0,0 @@
-<?php
-namespace Base\OAuthClientBundle\Security;
-
-use Symfony\Component\Security\Core\User\UserProviderInterface;
-use Symfony\Component\Security\Core\User\User;
-use Symfony\Component\Security\Core\User\UserInterface;
-use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
-
-class OAuthProxyUserProvider implements UserProviderInterface
-{
-    public function getUsernameForApiKey($apiKey)
-    {
-        // Look up the username based on the token in the database, via
-        // an API call, or do something entirely different
-        $username = "nose"; 
-
-        return $username;
-    }
-
-    public function loadUserByUsername($username)
-    {
-        return new User(
-            $username,
-            null,
-            // the roles for the user - you may choose to determine
-            // these dynamically somehow based on the user
-            array('ROLE_API')
-        );
-    }
-
-    public function refreshUser(UserInterface $user)
-    {
-        // this is used for storing authentication in the session
-        // but in this example, the token is sent in each request,
-        // so authentication can be stateless. Throwing this exception
-        // is proper to make things stateless
-        throw new UnsupportedUserException();
-    }
-
-    public function supportsClass($class)
-    {
-        return User::class === $class;
-    }
-}