def create_fake_token(user, scopes, client): expires_at = timezone.now() + timezone.timedelta(seconds=60) token = Token(user=user, client=client, expires_at=expires_at) token.scope = scopes token.save() return token
def create_api_preconditions_with_scope(user, scopes): assert isinstance(scopes, list) bearer = uuid.uuid4().hex client = Client(name='test_client') client.save() expires_at = timezone.now() + timezone.timedelta(days=30) t = Token(scope=scopes, access_token=bearer, user=user, expires_at=expires_at, client=client) t.save() return bearer
def create_token(user, client, scope, id_token_dic=None): """ Create and populate a Token object. Return a Token object. """ token = Token() token.user = user token.client = client payload = { 'iss': get_issuer(request=None), 'client': client.name, 'scope': ' '.join(map(str, scope)), 'exp': timezone.now() + timedelta(seconds=settings.get('OIDC_TOKEN_EXPIRE')) } if id_token_dic is not None: payload['id_token_dic'] = id_token_dic if user is not None: payload['user'] = user kid = settings.get('OIDC_SECRET_KEY') myToken = jwt.encode(payload, settings.get('OIDC_SECRET_KEY'), headers={'kid': kid}) logging.error(myToken.decode()) token.access_token = myToken.decode() if id_token_dic is not None: token.id_token = id_token_dic token.refresh_token = uuid.uuid4().hex token.expires_at = timezone.now() + timedelta( seconds=settings.get('OIDC_TOKEN_EXPIRE')) token.token_refresh_expires_at = timezone.now() + timedelta( seconds=settings.get('OIDC_TOKEN_REFRESH_EXPIRE')) token.scope = scope return token
def create_token(user, client, scope, id_token_dic=None, request=None, session_state=None): """ Create and populate a Token object. Return a Token object. """ token = Token() token.user = user token.client = client token.scope = scope if session_state is not None: token.session_state = session_state #add token as a jwt instead of uuid #token.access_token = uuid.uuid4().hex nonce = id_token_dic[ 'nonce'] if id_token_dic and 'nonce' in id_token_dic else '' at_hash = id_token_dic[ 'at_hash'] if id_token_dic and 'at_hash' in id_token_dic else '' token.access_token = create_jwt_access_token(token, user, client, nonce=nonce, at_hash=at_hash, request=request, scope=scope, session_state=session_state) if id_token_dic is not None: token.id_token = id_token_dic token.refresh_token = uuid.uuid4().hex token.expires_at = timezone.now() + timedelta( seconds=settings.get('OIDC_TOKEN_EXPIRE')) return token
def create_token(user, client, scope, id_token_dic=None): """ Create and populate a Token object. Return a Token object. """ token = Token() token.user = user token.client = client token.access_token = uuid.uuid4().hex if id_token_dic is not None: token.id_token = id_token_dic token.refresh_token = uuid.uuid4().hex token.expires_at = timezone.now() + timedelta( seconds=settings.get('OIDC_TOKEN_EXPIRE')) token.scope = scope return token