Beispiel #1
0
def oauth_make_token(user, auth_client, scope, user_session=None):
    # Look for an existing token
    token = auth_client.authtoken_for(user, user_session)

    # If token exists, add to the existing scope
    if token:
        token.add_scope(scope)
    else:
        # If there's no existing token, create one
        if auth_client.confidential:
            token = AuthToken(user=user,
                              auth_client=auth_client,
                              scope=scope,
                              token_type='bearer')
            token = failsafe_add(db.session,
                                 token,
                                 user=user,
                                 auth_client=auth_client)
        elif user_session:
            token = AuthToken(
                user_session=user_session,
                auth_client=auth_client,
                scope=scope,
                token_type='bearer',
            )
            token = failsafe_add(db.session,
                                 token,
                                 user_session=user_session,
                                 auth_client=auth_client)
        else:
            raise ValueError("user_session not provided")
    return token
Beispiel #2
0
def oauth_make_token(user, client, scope, user_session=None):
    # Look for an existing token
    if client.confidential:
        token = AuthToken.query.filter_by(user=user, client=client).first()
    elif user_session:
        token = AuthToken.query.filter_by(user_session=user_session,
                                          client=client).first()
    else:
        raise ValueError("user_session not provided")

    # If token exists, add to the existing scope
    if token:
        token.add_scope(scope)
    else:
        # If there's no existing token, create one
        if client.confidential:
            token = AuthToken(user=user,
                              client=client,
                              scope=scope,
                              token_type='bearer')
            token = failsafe_add(db.session, token, user=user, client=client)
        elif user_session:
            token = AuthToken(user_session=user_session,
                              client=client,
                              scope=scope,
                              token_type='bearer')
            token = failsafe_add(db.session,
                                 token,
                                 user_session=user_session,
                                 client=client)
    # TODO: Look up Resources for items in scope; look up their providing clients apps,
    # and notify each client app of this token
    return token
Beispiel #3
0
def oauth_make_token(user, client, scope):
    token = AuthToken.query.filter_by(user=user, client=client).first()
    if token:
        token.add_scope(scope)
    else:
        token = AuthToken(user=user, client=client, scope=scope, token_type='bearer')
        db.session.add(token)
    # TODO: Look up Resources for items in scope; look up their providing clients apps,
    # and notify each client app of this token
    return token