Skip to content

Instantly share code, notes, and snippets.

@phucpnt
Last active October 14, 2015 03:48
Show Gist options
  • Save phucpnt/928083bd72da16ae2d9a to your computer and use it in GitHub Desktop.
Save phucpnt/928083bd72da16ae2d9a to your computer and use it in GitHub Desktop.
yii2-eauth instagram oauth2 service
<?php
/**
* @author PhucPNT. <mail@phucpnt.com>
*/
namespace nodge\eauth\services;
use nodge\eauth\oauth2\Service;
use OAuth\Common\Token\TokenInterface;
use OAuth\OAuth2\Service\ServiceInterface;
/**
* LinkedIn provider class.
*
* @package application.extensions.eauth.services
*/
class InstagramOAuth2Service extends Service
{
/**
* Defined scopes
*
* @link https://instagram.com/developer/authentication/
*/
const SCOPE_BASIC = 'basic';
const SCOPE_COMMENTS = 'comments';
const SCOPE_RELATIONSHIPS = 'relationships';
const SCOPE_LIKES = 'likes';
protected $name = 'instagram';
protected $title = 'Instagram';
protected $type = 'OAuth2';
protected $jsArguments = array('popup' => array('width' => 900, 'height' => 550));
protected $popupDisplayName = false;
protected $scopes = array(self::SCOPE_BASIC);
protected $providerOptions = array(
'authorize' => 'https://api.instagram.com/oauth/authorize/',
'access_token' => 'https://api.instagram.com/oauth/access_token',
);
protected $baseApiUrl = 'https://api.instagram.com/v1/';
protected $tokenDefaultLifetime = TokenInterface::EOL_NEVER_EXPIRES;
protected function fetchAttributes()
{
$info = $this->makeSignedRequest('users/self', array(
'query' => array(
'format' => 'json',
),
));
$data = $info['data'];
$this->attributes = array_merge($this->attributes, [
'id' => $data['id'],
'username' => $data['username'],
'full_name' => $data['full_name'],
'profile_picture' => $data['profile_picture'],
'bio' => $data['bio'],
'website' => $data['website'],
'counts' => $data['counts']
]);
return true;
}
/**
* @return int
*/
public function getAuthorizationMethod()
{
return ServiceInterface::AUTHORIZATION_METHOD_QUERY_STRING;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment