summaryrefslogtreecommitdiff
path: root/controllers
diff options
context:
space:
mode:
authorAaron Parecki <aaron@parecki.com>2014-12-25 18:50:34 -0800
committerAaron Parecki <aaron@parecki.com>2014-12-25 18:50:34 -0800
commit430609b9005bb93ce2c6b21405cea0ede2b17a9d (patch)
tree090b64c2242ba5e8bbe8342a9a9494dcbeb1bf41 /controllers
parent2cd148c792a47fea18d760b723d23569ae52d390 (diff)
adds instagram auth
Diffstat (limited to 'controllers')
-rw-r--r--controllers/controllers.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/controllers/controllers.php b/controllers/controllers.php
index 18da149..47fd614 100644
--- a/controllers/controllers.php
+++ b/controllers/controllers.php
@@ -333,3 +333,43 @@ $app->get('/auth/twitter/callback', function() use($app) {
$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');
+ }
+});
+