Skip to content
This repository has been archived by the owner on Apr 9, 2023. It is now read-only.

Commit

Permalink
fix ws jose integration
Browse files Browse the repository at this point in the history
  • Loading branch information
vangheem committed Nov 23, 2016
1 parent 8058240 commit f397597
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
30 changes: 14 additions & 16 deletions src/plone.server/plone/server/api/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,23 @@
logger = logging.getLogger(__name__)


def generate_websocket_token(self, real_token):
exp = datetime.utcnow() + timedelta(
seconds=self._websockets_ttl)

claims = {
'iat': int(datetime.utcnow().timestamp()),
'exp': int(exp.timestamp()),
'token': real_token
}
jwe = jose.encrypt(claims, app_settings['rsa']['priv'])
token = jose.serialize_compact(jwe)
return token.decode('utf-8')
class WebsocketGetToken(Service):
_websockets_ttl = 60

def generate_websocket_token(self, real_token):
exp = datetime.utcnow() + timedelta(
seconds=self._websockets_ttl)

class WebsocketGetToken(Service):
claims = {
'iat': int(datetime.utcnow().timestamp()),
'exp': int(exp.timestamp()),
'token': real_token
}
jwe = jose.encrypt(claims, app_settings['rsa']['priv'])
token = jose.serialize_compact(jwe)
return token.decode('utf-8')

async def __call__(self):
# Get app root
app = self.request.app.router._root
# Get token
header_auth = self.request.headers.get('AUTHORIZATION')
token = None
Expand All @@ -48,7 +46,7 @@ async def __call__(self):
token = encoded_token.encode('ascii')

# Create ws token
new_token = app.generate_websocket_token(token)
new_token = self.generate_websocket_token(token)
return {
"token": new_token
}
Expand Down
1 change: 1 addition & 0 deletions src/plone.server/plone/server/auth/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import hashlib
import uuid
import logging


def hash_password(password, salt=None):
Expand Down
1 change: 0 additions & 1 deletion src/plone.server/plone/server/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def __init__(self, config_file):
self._dbs = {}
self._config_file = config_file
self._async_utilities = {}
self._websockets_ttl = 60

def add_async_utility(self, config):
interface = import_class(config['provides'])
Expand Down

0 comments on commit f397597

Please sign in to comment.