예제 #1
0
def create_token(user, client, scope, id_token_dic=None, ae=None, rid=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 ae is not None:
        token.ae = ae

    if rid is not None:
        token.rid = rid

    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
예제 #2
0
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
예제 #3
0
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
예제 #4
0
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