Skip to content

Commit 14a8d92

Browse files
committed
Add method to retrieve Kerberos ticket cache
1 parent ed8a654 commit 14a8d92

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

dash_auth/plotly_auth.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import absolute_import
22

3+
import base64
4+
import datetime
35
import os
46
import time
57

@@ -14,7 +16,7 @@
1416
import dash_core_components as dcc
1517
from dash.dependencies import Output, Input
1618

17-
from .oauth import OAuthBase
19+
from .oauth import OAuthBase, need_request_context
1820

1921
from . import api_requests
2022

@@ -150,6 +152,23 @@ def wrap(*args, **kwargs):
150152
def check_view_access(self, oauth_token):
151153
return check_view_access(oauth_token, self._dash_app['fid'])
152154

155+
@need_request_context
156+
def get_kerberos_ticket_cache(self):
157+
token = flask.request.cookies.get('plotly_oauth_token')
158+
159+
res = api_requests.get(
160+
'/v2/users/current?kerberos=1',
161+
headers={'Authorization': 'Bearer {}'.format(token)},
162+
)
163+
res_json = res.json()
164+
165+
expiry_str = res_json['kerberos_ticket_expiry']
166+
expiry = datetime.datetime.strptime(expiry_str, '%Y-%m-%dT%H:%M:%SZ')
167+
if expiry < datetime.datetime.utcnow():
168+
raise Exception('Kerberos ticket has expired.')
169+
170+
return base64.b64decode(res_json['kerberos_ticket_cache'])
171+
153172
def logout(self):
154173
token = flask.request.cookies.get('plotly_oauth_token')
155174
data = {

0 commit comments

Comments
 (0)