Ad

Laravel Socialite HTTPS Twitter Avatar

I am using laravel 5.0 and utlising the socialite extension to enable twitter login. I encountered a problem with the retrieval of the users twitter profile picture.

The url for the profile picture I receive from twitter is in the following format.

http://pbs.twimg.com/profile_images/662983942727999489/q5I9DMyE_normal.png

This is saved to my db and shown when the user logs into their account. The problem is this image is serving over HTTP and is producing browser warnings when users are accessing their account, as not all the page content is served over HTTPS.

Is there any way to save the twitter profile picture with HTTPS compared to HTTP.

 $user = User::create([
            'provider_id' => $userData->id,
            'name' => $userData->name,
            'username' => $userData->nickname,
            'email' => $userData->email,
            'avatar' => $userData->avatar,
            'active' => 1,
        ]);

I save the user twitter data to my db as shown above and it the $userData->avatar part which is saving the HTTP url.

I can't seem to work a way around this and can't find much documentation on the issue. Any help would be appreciated.

Ad

Answer

Well, verifying this url, it seems simple https:// for the same url works, so you can do:

$user = User::create([
    'provider_id' => $userData->id,
    'name' => $userData->name,
    'username' => $userData->nickname,
    'email' => $userData->email,
    'avatar' => str_replace('http://','https://',$userData->avatar),
    'active' => 1,
]);
Ad
source: stackoverflow.com
Ad