forked from liftoff/GateOne
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BIG CHANGE TO GOOGLE AUTH: Google has discontinued their old OAuth1 s…
…ervice. For this reason I have switched the code to use their new OAuth2 service. In order to use it though you *must* register a Google "project" for your Gate One server and add an origin and auth callback. If you configure Gate One to use Google authentication and don't have the necessary settings it will log a set of instructions to get it working. Updated documentation is forthcoming. terminal_input.js: Added "GateOne.Input" as a proper dependency to the `SuperSandbox()` call. This probably isn't necessary since application plugins get loaded much later than gateone_input.js would ever be but it's good form nonetheless. terminal.js: Added 'term' (terminal number) to the message data that gets sent to the WebWorker inside of `GateOne.Terminal.updateTerminalAction()`. terminal.js: Added a `GateOne.Terminal.lastLines(n, term)` which will give you the last *n* _actual_ lines of the given *term* (e.g. the line with the shell prompt). This is what most people want inside their plugins when performing pattern matching looking for the shell prompt (so they know when they can execute a command). app_terminal.py: Added a 'term' keyword argument to plugin_command_hooks and plugin_log_metadata_hooks so that value will be available to plugins when using those hooks.
- Loading branch information
Showing
7 changed files
with
108 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
__version_info__ = (1, 2, 0) | ||
__license__ = "AGPLv3" # ...or proprietary (see LICENSE.txt) | ||
__author__ = 'Dan McDougall <[email protected]>' | ||
__commit__ = "20140609191913" # Gets replaced by git (holds the date/time) | ||
__commit__ = "20140609214034" # Gets replaced by git (holds the date/time) | ||
|
||
import os | ||
GATEONE_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,7 @@ | |
""" | ||
|
||
# Import stdlib stuff | ||
import os, re, logging | ||
import os, re, logging, json | ||
try: | ||
from urllib import quote | ||
except ImportError: # Python 3 | ||
|
@@ -91,6 +91,7 @@ | |
import tornado.auth | ||
import tornado.escape | ||
import tornado.httpclient | ||
import tornado.gen | ||
|
||
# Localization support | ||
_ = get_translation() | ||
|
@@ -283,21 +284,36 @@ def get(self): | |
self.write('unauthenticated') | ||
self.finish() | ||
|
||
class GoogleAuthHandler(BaseAuthHandler, tornado.auth.GoogleMixin): | ||
|
||
class GoogleAuthHandler(BaseAuthHandler, tornado.auth.GoogleOAuth2Mixin): | ||
""" | ||
Google authentication handler using Tornado's built-in GoogleMixin (fairly | ||
boilerplate). | ||
Google authentication handler using Tornado's built-in GoogleOAuth2Mixin | ||
(fairly boilerplate). | ||
""" | ||
@tornado.web.asynchronous | ||
@tornado.gen.coroutine | ||
def get(self): | ||
""" | ||
Sets the 'user' cookie with an appropriate *upn* and *session* and any | ||
other values that might be attached to the user object given to us by | ||
Google. | ||
""" | ||
self.base_url = "{protocol}://{host}:{port}{url_prefix}".format( | ||
protocol=self.request.protocol, | ||
host=self.request.host, | ||
port=self.settings['port'], | ||
url_prefix=self.settings['url_prefix']) | ||
if 'https://' in self.base_url: | ||
if ':443/' in self.base_url: | ||
# Get rid of the 443 (it's assumed since https) | ||
self.base_url = self.base_url.replace(':443', '', 1) | ||
if 'http://' in self.base_url: | ||
if ':80/' in self.base_url: | ||
# Get rid of the 443 (it's assumed since https) | ||
self.base_url = self.base_url.replace(':80', '', 1) | ||
redirect_uri = "{base_url}auth".format(base_url=self.base_url) | ||
check = self.get_argument("check", None) | ||
if check: | ||
self.set_header ('Access-Control-Allow-Origin', '*') | ||
self.set_header('Access-Control-Allow-Origin', '*') | ||
user = self.get_current_user() | ||
if user: | ||
logging.debug('GoogleAuthHandler: user is authenticated') | ||
|
@@ -314,26 +330,50 @@ def get(self): | |
self.clear_cookie('gateone_user') | ||
self.user_logout(user, logout_url) | ||
return | ||
if self.get_argument("openid.mode", None): | ||
self.get_authenticated_user(self._on_auth) | ||
return | ||
self.authenticate_redirect( | ||
ax_attrs=["name", "email", "language", "username"]) | ||
if self.get_argument('code', False): | ||
user = yield self.get_authenticated_user( | ||
redirect_uri=redirect_uri, | ||
code=self.get_argument('code')) | ||
if not user: | ||
self.clear_all_cookies() | ||
raise tornado.web.HTTPError(500, 'Google auth failed') | ||
access_token = str(user['access_token']) | ||
http_client = self.get_auth_http_client() | ||
response = yield http_client.fetch( | ||
'https://www.googleapis.com/oauth2/v1/userinfo?access_token=' | ||
+access_token) | ||
if not response: | ||
self.clear_all_cookies() | ||
raise tornado.web.HTTPError(500, 'Google auth failed') | ||
user = json.loads(response.body.decode('utf-8')) | ||
self._on_auth(user) | ||
else: | ||
yield self.authorize_redirect( | ||
redirect_uri=redirect_uri, | ||
client_id=self.settings['google_oauth']['key'], | ||
scope=['email'], | ||
response_type='code', | ||
extra_params={'approval_prompt': 'auto'}) | ||
|
||
def _on_auth(self, user): | ||
""" | ||
Just a continuation of the get() method (the final step where it | ||
actually sets the cookie). | ||
""" | ||
logging.debug("GoogleAuthHandler.on_auth(%s)" % user) | ||
if not user: | ||
raise tornado.web.HTTPError(500, _("Google auth failed")) | ||
# NOTE: Google auth 'user' will be a dict like so: | ||
# user = { | ||
# 'locale': u'en-us', | ||
# 'first_name': u'Dan', | ||
# 'last_name': u'McDougall', | ||
# 'name': u'Dan McDougall', | ||
# 'email': u'[email protected]'} | ||
# user = {'given_name': 'Joe', | ||
# 'verified_email': True, | ||
# 'hd': 'example.com', | ||
# 'gender': 'male', | ||
# 'email': '[email protected]', | ||
# 'name': 'Joe Schmoe', | ||
# 'picture': 'https://lh6.googleusercontent.com/path/to/some.jpg', | ||
# 'id': '999999999999999999999', | ||
# 'family_name': 'Schmoe', | ||
# 'link': 'https://plus.google.com/999999999999999999999'} | ||
user['upn'] = user['email'] # Use the email for the upn | ||
self.user_login(user) | ||
next_url = self.get_argument("next", None) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
__version_info__ = (1, 2, 0) | ||
__license__ = "AGPLv3" # ...or proprietary (see LICENSE.txt) | ||
__author__ = 'Dan McDougall <[email protected]>' | ||
__commit__ = "20140609191913" # Gets replaced by git (holds the date/time) | ||
__commit__ = "20140609214034" # Gets replaced by git (holds the date/time) | ||
|
||
# NOTE: Docstring includes reStructuredText markup for use with Sphinx. | ||
__doc__ = '''\ | ||
|
@@ -3695,6 +3695,27 @@ def __init__(self, settings, **kwargs): | |
AuthHandler = PAMAuthHandler | ||
elif settings['auth'] == 'google': | ||
AuthHandler = GoogleAuthHandler | ||
if 'google_oauth' not in tornado_settings: | ||
logging.error(_( | ||
'In order to use Google authentication you must create ' | ||
'a Google project for your installation and add:\n\t' | ||
'{"google_oauth": {"key": "<YOUR CLIENT ID>", "secret":' | ||
' "<YOUR CLIENT SECRET>"}} to your ' | ||
'20authentication.conf (under the "gateone" section).')) | ||
logging.info(_( | ||
'To create a Google auth client ID and secret go to: ' | ||
'https://console.developers.google.com/ and click on ' | ||
'"APIs and Auth". Then click "Create New Client ID".' | ||
' Set the "JavaScript Origins" value to your Gate One ' | ||
'server\'s address and the "Redirect URIs" to https://' | ||
'<your Gate One server FQDN>/auth')) | ||
logging.info(_( | ||
'For example, if your "JavaScript Origins" is: ' | ||
'https://gateone.example.com/')) | ||
logging.info(_( | ||
'Your "Redirect URIs" would be: ' | ||
'https://gateone.example.com/auth')) | ||
sys.exit(1) | ||
elif settings['auth'] == 'cas': | ||
AuthHandler = CASAuthHandler | ||
elif settings['auth'] == 'ssl': | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.