Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Login Failed, #88

Closed
capripio opened this issue Apr 22, 2016 · 29 comments
Closed

Login Failed, #88

capripio opened this issue Apr 22, 2016 · 29 comments

Comments

@capripio
Copy link

I've tried to use pins create method and I got following error:

AuthException in ProviderLoginCheckWrapper.php line 54: You must log in before.

Yes I have used login function before calling this method and I get return true (as I assume its successfully logged in).

Currently I am using XAMPP

@seregazhuk
Copy link
Owner

seregazhuk commented Apr 22, 2016

Hi, I've checked now, everything seems to be working with the latest version, can you show your code?
What is output of print_r($bot->getLastError());?

@capripio
Copy link
Author

$bot = PinterestBot::create();
$boards = $bot->boards->forUser('USER GOES HERE');
$bot->login('email@email.com', 'passwordGoesHere');
$bot->pins->create($book->img_url, $boards[0]['id'], $desc);

@capripio
Copy link
Author

I've used it with laravel.

@seregazhuk
Copy link
Owner

Very strange. I've just checked it in Laravel.
As a quick solution you may comment 34 line in /Api/Providers/ProviderLoginCheckWrapper.php and try. I'll continue research for bugs.

@capripio
Copy link
Author

yes, I did try that, but it doesn't make pin. Let me retry again and update, I've missed something.

@capripio
Copy link
Author

capripio commented Apr 22, 2016

So I dig deeper in login method, here is the response I get at line 109 in Pinners.php

Might help you

array:5 [▼
"request_identifier" => "224645968114"
"resource_data_cache" => []
"resource" => array:2 [▼
"name" => "UserSessionResource"
"options" => array:3 [▼
"username_or_email" => "EMAIL HERE"
"bookmarks" => array:1 [▼
0 => "-end-"
]
"password" => "PASSWORD HERE"
]
]
"client_context" => array:39 [▼
"origin" => "https://nl.pinterest.com"
"unauth_id" => "89e7c9d2b449458cb3f2ed1bacfa280a"
"is_retina" => false
"user_agent_platform" => "other"
"sterling_admin_mode_view_as" => null
"is_authenticated" => true
"allow_image_prioritization" => true
"browser_locale" => "en-US"
"deep_link_action" => null
"triggerable_experiments" => array:201 [▶]
"visible_url" => "/login/"
"is_tablet_agent" => false
"utm_campaign" => null
"browser_type" => 4
"deep_link" => ""
"site_type" => 0
"from_open_in_app_click" => null
"invite_code" => null
"use_react" => true
"locale" => "en-US"
"utm_medium" => null
"giftwrap_holdout" => false
"app_version" => "d6936eb"
"site_const" => array:5 [▶]
"real_ip" => "39.48.31.185"
"user_agent_is_ios_9_2_or_above" => false
"active_experiments" => array:2 [▼
"related_pins_closeup" => "enabled"
"render_using_react_3" => "enabled"
]
"user" => array:39 [▼
"is_employee" => false
"username" => "USERNAME HERE"
"last_name" => ""
"domain_verified" => false
"nags" => []
"image_medium_url" => "https://s-media-cache-ak0.pinimg.com/avatars/bookler4288_1461317847_75.jpg"
"has_password" => true
"full_name" => "FULL NAME HERE"
"image_small_url" => "https://s-media-cache-ak0.pinimg.com/avatars/bookler4288_1461317847_30.jpg"
"gplus_url" => null
"id" => "202310345669271373"
"is_write_banned" => false
"first_name" => "FULL NAME HERE"
"domain_url" => "URL HERE"
"has_seen_notifications" => false
"personalize_from_offsite_browsing" => true
"facebook_timeline_enabled" => false
"personalize_nux_from_offsite_browsing" => false
"connected_to_rakuten" => false
"facebook_id" => ""
"connected_to_google" => false
"is_partner" => false
"type" => "user"
"email" => "EMAIL HERE"
"image_large_url" => "https://s-media-cache-ak0.pinimg.com/avatars/bookler4288_1461317847_140.jpg"
"connected_to_yahoo" => false
"verified_identity" => []
"twitter_url" => null
"facebook_url" => null
"twitter_publish_enabled" => false
"ads_customize_from_conversion" => true
"facebook_publish_stream_enabled" => false
"connected_to_microsoft" => false
"gender" => "female"
"created_at" => "Fri, 22 Apr 2016 09:35:40 +0000"
"login_state" => 1
"website_url" => "WEBSITE LINK HERE"
"country" => "PK"
"extension_access_token" => null
]
"deep_link_default" => ""
"http_referrer" => "https://nl.pinterest.com/"
"is_mobile_agent" => false
"is_internal_ip" => false
"language" => "en"
"is_sterling_on_steroids" => false
"referrer" => null
"user_agent_can_use_native_app" => false
"browser_name" => "Firefox"
"country" => "PK"
"error_template_path" => "templates/error.nunjucks"
]
"resource_response" => array:2 [▼
"data" => array:1 [▼
"token_type" => "bearer"
]
"error" => null
]
]

@seregazhuk
Copy link
Owner

Yes, logged in successfully, let's debug. Next on line 115 place var_dump($this->request->isLoggedIn());
And in ProviderLoginCheckWrapper on line 53 var_dump($methodRequiresLogin && !$isLoggedIn);

@capripio
Copy link
Author

Line 115:

Request {#172
#userAgent: "Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
#http: CurlAdapter {#178
-curl: Unknown resource @243
}
#loggedIn: null
#cookieJar: "pinterest_cookie"
#options: array:11 [▼
10018 => "Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
19913 => 1
64 => 0
52 => 1
10102 => "gzip,deflate"
10023 => array:11 [▼
0 => "Accept: application/json, text/javascript, /; q=0.01"
1 => "Accept-Language: en-US,en;q=0.5"
2 => "DNT: 1"
3 => "Host: nl.pinterest.com"
4 => "Content-Type: application/x-www-form-urlencoded; charset=UTF-8"
5 => "X-Pinterest-AppState: active"
6 => "X-NEW-APP: 1"
7 => "X-APP-VERSION: 04cf8cc"
8 => "X-Requested-With: XMLHttpRequest"
9 => "X-CSRFToken: 1234"
10 => "Cookie: csrftoken=1234;"
]
10016 => "https://nl.pinterest.com/"
10031 => "pinterest_cookie"
10082 => "pinterest_cookie"
47 => 1
10015 => "source_url=%2Flogin%2F&data=%7B%22options%22%3A%7B%22username_or_email%22%3A%22social%40bookler.xyz%22%2C%22password%22%3A%22windows%22%7D%2C%22context%22%3A%7B%7D%7D"
]
+csrfToken: null
#requestHeaders: array:9 [▼
0 => "Accept: application/json, text/javascript, /; q=0.01"
1 => "Accept-Language: en-US,en;q=0.5"
2 => "DNT: 1"
3 => "Host: nl.pinterest.com"
4 => "Content-Type: application/x-www-form-urlencoded; charset=UTF-8"
5 => "X-Pinterest-AppState: active"
6 => "X-NEW-APP: 1"
7 => "X-APP-VERSION: 04cf8cc"
8 => "X-Requested-With: XMLHttpRequest"
]
}

@capripio
Copy link
Author

53 returns false, which cause exception of auth

@seregazhuk
Copy link
Owner

I see, i think it is because of rights. When logged in request is made, it saves cookies on disk to parse and to get token from it. In Request.php on 185 line. I think script has no rights to create files, so no token has been parsed.
It's my fault, I should raise an exception here. Please check rights on your directory.

@seregazhuk
Copy link
Owner

Script saves cookies in it's root path in pinterest_cookie file.

@capripio
Copy link
Author

are you talking about following function? Its doesn't seems to called, i can't debug it here. and I am using Windows I don't think any issue with permission?

public static function createQuery(array $data = [], $sourceUrl = '/', $bookmarks = [])
{
    $request = self::createRequestData($data, $sourceUrl, $bookmarks);

    return UrlHelper::buildRequestString($request);
}

@seregazhuk
Copy link
Owner

No, Api\Request.php line 185:

public function setLoggedIn()
    {
        $this->csrfToken = CsrfHelper::getTokenFromFile($this->cookieJar);   // <--- parsing token from file
        if (!empty($this->csrfToken)) {
            $this->loggedIn = true;
        }

        return $this;
    }

I think the problem is here. No token has been parsed.

@capripio
Copy link
Author

well this code intersect with in line no. 158.

@capripio
Copy link
Author

public function setLoggedIn()
{
    $this->csrfToken = CsrfHelper::getTokenFromFile($this->cookieJar);
    if (!empty($this->csrfToken)) {
        $this->loggedIn = true;
    }

    return $this;
}

@seregazhuk
Copy link
Owner

Yes, here. I think $this->csrfToken is empty in your case.

@capripio
Copy link
Author

yes it does.

@seregazhuk
Copy link
Owner

try to change directory permissions

@capripio
Copy link
Author

can you tell me when your code store file I might debug it out!

@seregazhuk
Copy link
Owner

If you are using Laravel, it will be in public folder
534f908855

@capripio
Copy link
Author

hmm that's strange I've provided right too all users still unable to do login.

@capripio
Copy link
Author

however thanks for help, since its seems issue on my side, I must have miss something. I will close this bug and debug whole thing in morning.
Have a good day!
Good Night.

@seregazhuk
Copy link
Owner

Ok, good luck to you! May be try manually create this file empty in laravels public folder.

@seregazhuk
Copy link
Owner

@capripio one more solution. I think it will solve problems with permissions. In file Api/Request.php in constructor change cookieJar for curl:

 /**
     * @param HttpInterface $http
     * @param string|null   $userAgent
     */
    public function __construct(HttpInterface $http, $userAgent = null)
    {
        $this->http = $http;
        if ($userAgent !== null) {
            $this->userAgent = $userAgent;
        }
        // $this->cookieJar = self::COOKIE_NAME; <--- before
        $this->cookieJar = tempnam(sys_get_temp_dir(), self::COOKIE_NAME); // <-- after
    }

@capripio
Copy link
Author

ok let me try it now!

@capripio
Copy link
Author

it's worked! I guess I need to learn about 2 new functions 👍

@seregazhuk
Copy link
Owner

Oh, that's great!)

@capripio
Copy link
Author

Thanks! finally I can sleep now :D you know what I mean! Good Night and Thanks again!

@seregazhuk
Copy link
Owner

Good night) I've published a new release of library with this fix. Update tomorrow, and there will be no need to change library source.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants