adds instagram auth
This commit is contained in:
parent
2cd148c792
commit
430609b900
5 changed files with 122 additions and 8 deletions
|
@ -9,7 +9,8 @@
|
||||||
"indieauth/client": "0.1.3",
|
"indieauth/client": "0.1.3",
|
||||||
"mpratt/relativetime": ">=1.0",
|
"mpratt/relativetime": ">=1.0",
|
||||||
"firebase/php-jwt": "dev-master",
|
"firebase/php-jwt": "dev-master",
|
||||||
"ruudk/twitter-oauth": "dev-master"
|
"ruudk/twitter-oauth": "dev-master",
|
||||||
|
"andreyco/instagram": "3.*"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"files": [
|
"files": [
|
||||||
|
|
45
composer.lock
generated
45
composer.lock
generated
|
@ -3,8 +3,51 @@
|
||||||
"This file locks the dependencies of your project to a known state",
|
"This file locks the dependencies of your project to a known state",
|
||||||
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
|
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
|
||||||
],
|
],
|
||||||
"hash": "502847c033f5a54c69a6a1a51d26e894",
|
"hash": "f2f8fdb671b52ce22dc0a5e133f9a13d",
|
||||||
"packages": [
|
"packages": [
|
||||||
|
{
|
||||||
|
"name": "andreyco/instagram",
|
||||||
|
"version": "v3.2",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/Andreyco/Instagram-for-PHP.git",
|
||||||
|
"reference": "726e724c51301410873d9bae9c659a0597ca47e4"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/Andreyco/Instagram-for-PHP/zipball/726e724c51301410873d9bae9c659a0597ca47e4",
|
||||||
|
"reference": "726e724c51301410873d9bae9c659a0597ca47e4",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-curl": "*",
|
||||||
|
"php": ">=5.3.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Andreyco\\Instagram\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"BSD-4-Clause"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Andrej Badin",
|
||||||
|
"email": "contact@andrejbadin.com",
|
||||||
|
"homepage": "http://andrejbadin.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "An easy-to-use PHP Class for accessing Instagram's API.",
|
||||||
|
"homepage": "https://github.com/Andreyco/Instagram",
|
||||||
|
"keywords": [
|
||||||
|
"api",
|
||||||
|
"instagram"
|
||||||
|
],
|
||||||
|
"time": "2014-07-14 19:53:19"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "firebase/php-jwt",
|
"name": "firebase/php-jwt",
|
||||||
"version": "dev-master",
|
"version": "dev-master",
|
||||||
|
|
|
@ -333,3 +333,43 @@ $app->get('/auth/twitter/callback', function() use($app) {
|
||||||
$app->redirect('/settings');
|
$app->redirect('/settings');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$app->get('/auth/instagram', function() use($app) {
|
||||||
|
if($user=require_login($app, false)) {
|
||||||
|
|
||||||
|
$instagram = instagram_client();
|
||||||
|
|
||||||
|
// If there is an existing Instagram auth token, check if it's valid
|
||||||
|
if($user->instagram_access_token) {
|
||||||
|
$instagram->setAccessToken($user->instagram_access_token);
|
||||||
|
$igUser = $instagram->getUser();
|
||||||
|
|
||||||
|
if($igUser && $igUser->meta->code == 200) {
|
||||||
|
$app->response()->body(json_encode(array(
|
||||||
|
'result' => 'ok',
|
||||||
|
'username' => $igUser->data->username
|
||||||
|
)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$app->response()->body(json_encode(array(
|
||||||
|
'result' => 'error',
|
||||||
|
'url' => $instagram->getLoginUrl(array('basic','likes'))
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$app->get('/auth/instagram/callback', function() use($app) {
|
||||||
|
if($user=require_login($app)) {
|
||||||
|
$params = $app->request()->params();
|
||||||
|
|
||||||
|
$instagram = instagram_client();
|
||||||
|
$data = $instagram->getOAuthToken($params['code']);
|
||||||
|
$user->instagram_access_token = $data->access_token;
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
$app->redirect('/settings');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
|
@ -195,3 +195,14 @@ function relative_time($date) {
|
||||||
}
|
}
|
||||||
return $rel->timeAgo($date);
|
return $rel->timeAgo($date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function instagram_client() {
|
||||||
|
return new Andreyco\Instagram\Client(array(
|
||||||
|
'apiKey' => Config::$instagramClientID,
|
||||||
|
'apiSecret' => Config::$instagramClientSecret,
|
||||||
|
'apiCallback' => Config::$base_url . 'auth/instagram/callback',
|
||||||
|
'scope' => array('basic','likes'),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,8 @@
|
||||||
<h3>Twitter</h3>
|
<h3>Twitter</h3>
|
||||||
<input type="button" id="twitter-button" value="Checking" class="btn">
|
<input type="button" id="twitter-button" value="Checking" class="btn">
|
||||||
|
|
||||||
|
|
||||||
<!--
|
|
||||||
<h3>Instagram</h3>
|
<h3>Instagram</h3>
|
||||||
|
<input type="button" id="instagram-button" value="Checking" class="btn">
|
||||||
-->
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
|
@ -60,6 +57,10 @@ function save_facebook_token(token) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$(function(){
|
$(function(){
|
||||||
|
$("#facebook-button").click(function(){
|
||||||
|
FB.login(window.quillHandleFbLogin, {scope:'publish_actions'});
|
||||||
|
});
|
||||||
|
|
||||||
$.getJSON("/auth/twitter", function(data){
|
$.getJSON("/auth/twitter", function(data){
|
||||||
// Check if we're already authorized with twitter
|
// Check if we're already authorized with twitter
|
||||||
if(data && data.result == 'ok') {
|
if(data && data.result == 'ok') {
|
||||||
|
@ -81,8 +82,26 @@ $(function(){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#facebook-button").click(function(){
|
$.getJSON("/auth/instagram", function(data){
|
||||||
FB.login(window.quillHandleFbLogin, {scope:'publish_actions'});
|
// Check if we're already authorized with Instagram
|
||||||
|
if(data && data.result == 'ok') {
|
||||||
|
$("#instagram-button").val("Connected").addClass("btn-success");
|
||||||
|
} else if(data && data.url) {
|
||||||
|
$("#instagram-button").val("Sign In").data("url", data.url).addClass("btn-warning");
|
||||||
|
} else {
|
||||||
|
$("#instagram-button").val("Error").addClass("btn-danger");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#instagram-button").click(function(){
|
||||||
|
if($(this).data('url')) {
|
||||||
|
window.location = $(this).data('url');
|
||||||
|
} else {
|
||||||
|
$.getJSON("/auth/instagram", {login: 1}, function(data){
|
||||||
|
window.location = data.url;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue