Skip to content
This repository was archived by the owner on Jul 28, 2022. It is now read-only.
This repository was archived by the owner on Jul 28, 2022. It is now read-only.

Basic login seems to not be working #1

Open

Description

@posabsolute

When I try to login the script throw no errors,

but I am obviously not logged in as

var_dump($user->emails()->all());

report unauthorized

using
$user->setCredentials(new Authentication\Basic('username', 'password'));
$user->login();

Activity

  1. bsatoris commented on Jul 24, 2012

    @bsatoris

    I had the same issue -- it appears to be a design problem because authentication is not abstracted from Api. So for example, when you do:

    $user = new User();
    $user->setCredentials(new Authentication\Basic('username', 'password'));
    
    /* This causes $this->authenticated = TRUE and 
    $this->authenticator to be an instance of AuthenticationInterface
    in the Api class. All is good. */
    
    //this will work
    var_dump($user->isFollowing('octocat'));
    
    //this will not
    var_dump($user->emails()->all());
    

    Why won't the last call work? Because User::emails() instantiates a new instance of Email, which also extends from Api. So the instance variables $this->authenticator and $this->authenticated are set to their default values of null and FALSE for the instance of Api that we are now using. So when Api::doRequest() runs the authentication information is no longer there, and not passed with the request.

    For a one-off project I was doing I just implemented a hack in Api::doRequest() to set the credentials there, ensuring they are present in the requests I needed to make. The real solution is to abstract the authentication stuff out of Api.

        protected function doRequest($method, $url, $params, $headers)
        {
            $request = $this->transport->createRequest();
    
            $request->setMethod($method);
            $request->fromUrl($url);
            $request->addHeaders($headers);
            $request->setContent($params);
            //begin hack
            $this->setCredentials(new Authentication\Basic('username', 'password'));
            $this->login();
            //end hack
            if ($this->isAuthenticated() && null !== $this->authenticator)
            {
                $request = $this->authenticator->authenticate($request);
            }
    
            return $this->transport->send($request);
        }
    
  2. sorbing commented on Nov 7, 2013

    @sorbing

    Error: "Fatal error: Call to undefined method Buzz\Browser::createRequest() in /www/project/vendor/dsyph3r/github-api3-php/lib/GitHub/API/Api.php on line 232" for OAuth Credentials type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions