Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing people to get the authorization url instead of forcing the redirection #31

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions Instagram/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,26 @@ public function __construct( array $config = null, \Instagram\Net\ClientInterfac
* @access public
*/
public function authorize() {
header(
sprintf(
'Location:https://api.instagram.com/oauth/authorize/?client_id=%s&redirect_uri=%s&response_type=code&scope=%s',
$this->config['client_id'],
$this->config['redirect_uri'],
implode( '+', $this->config['scope'] )
)
);
header('Location:' . $this->getAuthorizationUrl());
exit;
}

/**
* getAuthorizationUrl
*
* Return the URL to request authorization from an Instagram user
* @return string
*/
public function getAuthorizationUrl()
{
return sprintf(
'https://api.instagram.com/oauth/authorize/?client_id=%s&redirect_uri=%s&response_type=code&scope=%s',
$this->config['client_id'],
$this->config['redirect_uri'],
implode( '+', $this->config['scope'] )
);
}

/**
* Get the access token
*
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,16 @@ All methods that access the API can throw exceptions. If the API request fails f

$auth->authorize();

- You can also just retrieve the authorisation URL and take care of the redirection yourself via

<b></b>

$auth->getAuthorizationUrl();


- This will redirect the user to the Instagram authorization page. After authorization Instagram will redirect the user to the url in `$auth_config['redirect_uri']` with a code that you will need to obtain an access token


<b></b>

$_SESSION['instagram_access_token'] = $auth->getAccessToken( $_GET['code'] );
Expand Down