mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-11 15:56:07 -07:00
Allow custom redirect uri with Facebook notifier
This commit is contained in:
parent
01791eac52
commit
b24e9a2185
4 changed files with 29 additions and 33 deletions
|
@ -136,14 +136,14 @@ from plexpy import helpers
|
||||||
cache: false,
|
cache: false,
|
||||||
async: true,
|
async: true,
|
||||||
complete: function (xhr, status) {
|
complete: function (xhr, status) {
|
||||||
$("#notification-config-modal").html(xhr.responseText);
|
$('#notification-config-modal').html(xhr.responseText);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#osxnotifyregister').click(function () {
|
$('#osxnotifyregister').click(function () {
|
||||||
var osx_notify_app = $("#osx_notify_app").val();
|
var osx_notify_app = $('#osx_notify_app').val();
|
||||||
$.get("/osxnotifyregister", { 'app': osx_notify_app }, function (data) { showMsg("<i class='fa fa-check'></i> " + data, false, true, 3000); });
|
$.get('/osxnotifyregister', { 'app': osx_notify_app }, function (data) { showMsg('<i class="fa fa-check"></i> ' + data, false, true, 3000); });
|
||||||
})
|
})
|
||||||
|
|
||||||
$('#save-notification-item').click(function () {
|
$('#save-notification-item').click(function () {
|
||||||
|
@ -163,12 +163,12 @@ from plexpy import helpers
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#twitterStep1').click(function () {
|
$('#twitterStep1').click(function () {
|
||||||
$.get("/twitterStep1", function (data) {window.open(data); })
|
$.get('/twitterStep1', function (data) {window.open(data); })
|
||||||
.done(function () { showMsg("<i class='fa fa-check'></i> Confirm Authorization. Check pop-up blocker if no response.", false, true, 3000); });
|
.done(function () { showMsg('<i class="fa fa-check"></i> Confirm Authorization. Check pop-up blocker if no response.', false, true, 3000); });
|
||||||
});
|
});
|
||||||
$('#twitterStep2').click(function () {
|
$('#twitterStep2').click(function () {
|
||||||
var twitter_key = $("#twitter_key").val();
|
var twitter_key = $('#twitter_key').val();
|
||||||
$.get("/twitterStep2", { 'key': twitter_key }, function (data) { showMsg("<i class='fa fa-check'></i> " + data, false, true, 3000); });
|
$.get('/twitterStep2', { 'key': twitter_key }, function (data) { showMsg('<i class="fa fa-check"></i> ' + data, false, true, 3000); });
|
||||||
});
|
});
|
||||||
|
|
||||||
function disableFacebookRequest() {
|
function disableFacebookRequest() {
|
||||||
|
@ -182,8 +182,8 @@ from plexpy import helpers
|
||||||
|
|
||||||
$('#facebookStep1').click(function () {
|
$('#facebookStep1').click(function () {
|
||||||
doAjaxCall('set_notification_config', $(this), 'tabs', true);
|
doAjaxCall('set_notification_config', $(this), 'tabs', true);
|
||||||
$.get("/facebookStep1", function (data) {window.open(data); })
|
$.get('/facebookStep1', function (data) { window.open(data); })
|
||||||
.done(function () { showMsg("<i class='fa fa-check'></i> Confirm Authorization. Check pop-up blocker if no response.", false, true, 3000); });
|
.done(function () { showMsg('<i class="fa fa-check"></i> Confirm Authorization. Check pop-up blocker if no response.', false, true, 3000); });
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#test_notifier').click(function () {
|
$('#test_notifier').click(function () {
|
||||||
|
@ -215,10 +215,10 @@ from plexpy import helpers
|
||||||
// Never send checkbox values directly, always substitute value in hidden input.
|
// Never send checkbox values directly, always substitute value in hidden input.
|
||||||
$('.checkboxes').click(function () {
|
$('.checkboxes').click(function () {
|
||||||
var configToggle = $(this).data('id');
|
var configToggle = $(this).data('id');
|
||||||
if ($(this).is(":checked")) {
|
if ($(this).is(':checked')) {
|
||||||
$("#"+configToggle).val(1);
|
$('#'+configToggle).val(1);
|
||||||
} else {
|
} else {
|
||||||
$("#"+configToggle).val(0);
|
$('#'+configToggle).val(0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -80,6 +80,7 @@ _CONFIG_DEFINITIONS = {
|
||||||
'EMAIL_ON_INTUP': (int, 'Email', 0),
|
'EMAIL_ON_INTUP': (int, 'Email', 0),
|
||||||
'ENABLE_HTTPS': (int, 'General', 0),
|
'ENABLE_HTTPS': (int, 'General', 0),
|
||||||
'FACEBOOK_ENABLED': (int, 'Facebook', 0),
|
'FACEBOOK_ENABLED': (int, 'Facebook', 0),
|
||||||
|
'FACEBOOK_REDIRECT_URI': (str, 'Facebook', ''),
|
||||||
'FACEBOOK_APP_ID': (str, 'Facebook', ''),
|
'FACEBOOK_APP_ID': (str, 'Facebook', ''),
|
||||||
'FACEBOOK_APP_SECRET': (str, 'Facebook', ''),
|
'FACEBOOK_APP_SECRET': (str, 'Facebook', ''),
|
||||||
'FACEBOOK_TOKEN': (str, 'Facebook', ''),
|
'FACEBOOK_TOKEN': (str, 'Facebook', ''),
|
||||||
|
|
|
@ -2020,23 +2020,11 @@ class Scripts(object):
|
||||||
class FacebookNotifier(object):
|
class FacebookNotifier(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.redirect_uri = plexpy.CONFIG.FACEBOOK_REDIRECT_URI
|
||||||
self.app_id = plexpy.CONFIG.FACEBOOK_APP_ID
|
self.app_id = plexpy.CONFIG.FACEBOOK_APP_ID
|
||||||
self.app_secret = plexpy.CONFIG.FACEBOOK_APP_SECRET
|
self.app_secret = plexpy.CONFIG.FACEBOOK_APP_SECRET
|
||||||
self.group_id = plexpy.CONFIG.FACEBOOK_GROUP
|
self.group_id = plexpy.CONFIG.FACEBOOK_GROUP
|
||||||
|
|
||||||
if plexpy.CONFIG.ENABLE_HTTPS:
|
|
||||||
protocol = 'https'
|
|
||||||
else:
|
|
||||||
protocol = 'http'
|
|
||||||
|
|
||||||
if plexpy.CONFIG.HTTP_HOST == '0.0.0.0':
|
|
||||||
host = 'localhost'
|
|
||||||
else:
|
|
||||||
host = plexpy.CONFIG.HTTP_HOST
|
|
||||||
|
|
||||||
self.redirect_url = '%s://%s:%i/facebookStep2' % (protocol, host, plexpy.CONFIG.HTTP_PORT)
|
|
||||||
|
|
||||||
|
|
||||||
def notify(self, subject, message):
|
def notify(self, subject, message):
|
||||||
if not subject or not message:
|
if not subject or not message:
|
||||||
return
|
return
|
||||||
|
@ -2048,7 +2036,7 @@ class FacebookNotifier(object):
|
||||||
|
|
||||||
def _get_authorization(self):
|
def _get_authorization(self):
|
||||||
return facebook.auth_url(app_id=self.app_id,
|
return facebook.auth_url(app_id=self.app_id,
|
||||||
canvas_url=self.redirect_url,
|
canvas_url=self.redirect_uri + '/facebookStep2',
|
||||||
perms=['user_managed_groups','publish_actions'])
|
perms=['user_managed_groups','publish_actions'])
|
||||||
|
|
||||||
def _get_credentials(self, code):
|
def _get_credentials(self, code):
|
||||||
|
@ -2058,7 +2046,7 @@ class FacebookNotifier(object):
|
||||||
# Request user access token
|
# Request user access token
|
||||||
api = facebook.GraphAPI(version='2.5')
|
api = facebook.GraphAPI(version='2.5')
|
||||||
response = api.get_access_token_from_code(code=code,
|
response = api.get_access_token_from_code(code=code,
|
||||||
redirect_uri=self.redirect_url,
|
redirect_uri=self.redirect_uri + '/facebookStep2',
|
||||||
app_id=self.app_id,
|
app_id=self.app_id,
|
||||||
app_secret=self.app_secret)
|
app_secret=self.app_secret)
|
||||||
access_token = response['access_token']
|
access_token = response['access_token']
|
||||||
|
@ -2072,7 +2060,7 @@ class FacebookNotifier(object):
|
||||||
plexpy.CONFIG.FACEBOOK_TOKEN = access_token
|
plexpy.CONFIG.FACEBOOK_TOKEN = access_token
|
||||||
plexpy.CONFIG.write()
|
plexpy.CONFIG.write()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.info(u"PlexPy Notifiers :: Error requesting Facebook access token: %s" % e)
|
logger.error(u"PlexPy Notifiers :: Error requesting Facebook access token: %s" % e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -2088,12 +2076,12 @@ class FacebookNotifier(object):
|
||||||
api.put_wall_post(profile_id=group_id, message=message)
|
api.put_wall_post(profile_id=group_id, message=message)
|
||||||
logger.info(u"PlexPy Notifiers :: Facebook notification sent.")
|
logger.info(u"PlexPy Notifiers :: Facebook notification sent.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.info(u"PlexPy Notifiers :: Error sending Facebook post: %s" % e)
|
logger.warn(u"PlexPy Notifiers :: Error sending Facebook post: %s" % e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
logger.info(u"PlexPy Notifiers :: Error sending Facebook post: No Facebook Group ID provided.")
|
logger.warn(u"PlexPy Notifiers :: Error sending Facebook post: No Facebook Group ID provided.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def return_config_options(self):
|
def return_config_options(self):
|
||||||
|
@ -2103,10 +2091,17 @@ class FacebookNotifier(object):
|
||||||
Facebook Developers</a> to create a new app using <strong>advanced setup</strong>.<br>\
|
Facebook Developers</a> to create a new app using <strong>advanced setup</strong>.<br>\
|
||||||
Step 2: Go to <strong>Settings > Advanced</strong> and fill in \
|
Step 2: Go to <strong>Settings > Advanced</strong> and fill in \
|
||||||
<strong>Valid OAuth redirect URIs</strong> with your PlexPy URL (i.e. http://localhost:8181).<br>\
|
<strong>Valid OAuth redirect URIs</strong> with your PlexPy URL (i.e. http://localhost:8181).<br>\
|
||||||
Step 3: Fill in the <strong>App ID</strong> and <strong>App Secret</strong> below.<br>\
|
Step 3: Fill in the <strong>PlexPy URL</strong> below with the exact same URL from Step 2.<br>\
|
||||||
Step 4: Click the <strong>Request Authorization</strong> button below.',
|
Step 4: Fill in the <strong>App ID</strong> and <strong>App Secret</strong> below.<br>\
|
||||||
|
Step 5: Click the <strong>Request Authorization</strong> button below.',
|
||||||
'input_type': 'help'
|
'input_type': 'help'
|
||||||
},
|
},
|
||||||
|
{'label': 'PlexPy URL',
|
||||||
|
'value': self.redirect_uri,
|
||||||
|
'name': 'facebook_redirect_uri',
|
||||||
|
'description': 'Your PlexPy URL. This will tell Facebook where to redirect you after authorization.',
|
||||||
|
'input_type': 'text'
|
||||||
|
},
|
||||||
{'label': 'Facebook App ID',
|
{'label': 'Facebook App ID',
|
||||||
'value': self.app_id,
|
'value': self.app_id,
|
||||||
'name': 'facebook_app_id',
|
'name': 'facebook_app_id',
|
||||||
|
|
|
@ -1312,7 +1312,7 @@ class WebInterface(object):
|
||||||
result = facebook._get_credentials(code)
|
result = facebook._get_credentials(code)
|
||||||
# logger.info(u"result: " + str(result))
|
# logger.info(u"result: " + str(result))
|
||||||
if result:
|
if result:
|
||||||
return "Key verification successful, you may close this page now."
|
return "Key verification successful, PlexPy can send notification to Facebook. You may close this page now."
|
||||||
else:
|
else:
|
||||||
return "Unable to verify key"
|
return "Unable to verify key"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue