From 7165f4b2ae1c855c6fa57ee6908376c1772b3b8c Mon Sep 17 00:00:00 2001 From: Jean-Christophe Cuvelier Date: Fri, 8 Nov 2013 10:33:28 +0100 Subject: [PATCH 1/4] Add Authorization URL function --- Instagram/Auth.php | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Instagram/Auth.php b/Instagram/Auth.php index 9cce45c..27e6428 100644 --- a/Instagram/Auth.php +++ b/Instagram/Auth.php @@ -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 * From d576ff23cdafcded12284cb68011d63e6e55596e Mon Sep 17 00:00:00 2001 From: Jean-Christophe Cuvelier Date: Fri, 8 Nov 2013 10:35:44 +0100 Subject: [PATCH 2/4] Add getAuthorizationUrl to the doc --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 55d3078..a3bac45 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,12 @@ All methods that access the API can throw exceptions. If the API request fails f - 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 +- You can also just retrieve the authorisation URL and take care of the redirection yourself via + + $auth->getAuthorizationUrl(); + + + $_SESSION['instagram_access_token'] = $auth->getAccessToken( $_GET['code'] ); From 29d8d6db1595b29070aebba6cbda1855fbafb61f Mon Sep 17 00:00:00 2001 From: Jean-Christophe Cuvelier Date: Fri, 8 Nov 2013 10:36:13 +0100 Subject: [PATCH 3/4] style fix --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a3bac45..b529fcc 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ All methods that access the API can throw exceptions. If the API request fails f - You can also just retrieve the authorisation URL and take care of the redirection yourself via + + $auth->getAuthorizationUrl(); From 60b9f637635044d0060d3660383d2837a4f5bea7 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Cuvelier Date: Fri, 8 Nov 2013 10:37:17 +0100 Subject: [PATCH 4/4] Doc logic revisited --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b529fcc..9eb28b3 100644 --- a/README.md +++ b/README.md @@ -37,14 +37,14 @@ All methods that access the API can throw exceptions. If the API request fails f $auth->authorize(); -- 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 - - You can also just retrieve the authorisation URL and take care of the redirection yourself via $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