Skip to content

Commit

Permalink
Add Instagram support
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwathan committed Oct 3, 2014
1 parent dec1338 commit 720d09d
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class EloquentOAuthServiceProvider extends ServiceProvider {
'github' => 'AdamWathan\\EloquentOAuth\\Providers\\GitHubProvider',
'google' => 'AdamWathan\\EloquentOAuth\\Providers\\GoogleProvider',
'linkedin' => 'AdamWathan\\EloquentOAuth\\Providers\\LinkedInProvider',
'instagram' => 'AdamWathan\\EloquentOAuth\\Providers\\InstagramProvider',
);

/**
Expand Down
84 changes: 84 additions & 0 deletions src/AdamWathan/EloquentOAuth/Providers/InstagramProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php namespace AdamWathan\EloquentOAuth\Providers;

use AdamWathan\EloquentOAuth\Exceptions\InvalidAuthorizationCodeException;

class InstagramProvider extends Provider
{
protected $authorizeUrl = "https://api.instagram.com/oauth/authorize";
protected $accessTokenUrl = "https://api.instagram.com/oauth/access_token";
protected $userDataUrl = "https://api.instagram.com/v1/users/self";
protected $scope = array(
'basic',
);

protected function getAuthorizeUrl()
{
return $this->authorizeUrl;
}

protected function getAccessTokenBaseUrl()
{
return $this->accessTokenUrl;
}

protected function getUserDataUrl()
{
return $this->userDataUrl;
}

protected function compileScopes()
{
return implode('+', $this->scope);
}

protected function parseTokenResponse($response)
{
$data = json_decode($response);
if (! isset($data->access_token)) {
throw new InvalidAuthorizationCodeException;
}
return $data->access_token;
}

protected function requestUserData()
{
$userData = parent::requestUserData();
return $userData;
}

protected function parseUserDataResponse($response)
{
$data = json_decode($response, true);
return $data['data'];
}

protected function userId()
{
return $this->getProviderUserData('id');
}

protected function nickname()
{
return $this->getProviderUserData('username');
}

protected function firstName()
{
return strstr($this->getProviderUserData('full_name'), ' ', true);
}

protected function lastName()
{
return substr(strstr($this->getProviderUserData('full_name'), ' '), 1);
}

protected function imageUrl()
{
return $this->getProviderUserData('profile_picture');
}

protected function email()
{
return null; // Impossible to get email from Instagram
}
}

0 comments on commit 720d09d

Please sign in to comment.