예제 #1
0
def token(args):
    """
    Generate an OAuth bearer token for the specified principal.

    This token is suitable for authenticating HTTP requests to the h API.

    For example, to authorize yourself as user seanh to your local dev instance
    of h do:

        hypothesis token --base 'http://*****:*****@localhost' conf/development.ini

    Then copy the output and pass it to the h API as the value of an
    X-Annotator-Auth-Token header.

    """
    from h.auth import get_client, generate_signed_token

    request = bootstrap(args)
    registry = request.registry

    request.client = get_client(request, registry.settings['h.client_id'])
    request.user = args.sub
    request.expires_in = args.ttl
    request.extra_credentials = {}

    token = generate_signed_token(request)

    print(token)
예제 #2
0
파일: script.py 프로젝트: hylhero/h
def token(args):
    """
    Generate an OAuth bearer token for the specified principal.

    This token is suitable for authenticating HTTP requests to the h API.

    For example, to authorize yourself as user seanh to your local dev instance
    of h do:

        hypothesis token --base 'http://*****:*****@localhost' conf/development.ini

    Then copy the output and pass it to the h API as the value of an
    X-Annotator-Auth-Token header.

    """
    from h.auth import get_client, generate_signed_token

    request = bootstrap(args)
    registry = request.registry

    request.client = get_client(request, registry.settings['h.client_id'])
    request.user = args.sub
    request.expires_in = args.ttl
    request.extra_credentials = {}

    token = generate_signed_token(request)

    print(token)
예제 #3
0
파일: auth_test.py 프로젝트: ningyifan/h
def test_get_client_missing(config):
    mock_factory = MagicMock()
    mock_factory.return_value = None
    registry = config.registry
    registry.registerUtility(mock_factory, interfaces.IClientFactory)
    request = testing.DummyRequest(registry=config.registry)
    assert auth.get_client(request, '9876') is None
    mock_factory.assert_called_with(request, '9876')
예제 #4
0
파일: auth_test.py 프로젝트: ningyifan/h
def test_get_client_missing(config):
    mock_factory = MagicMock()
    mock_factory.return_value = None
    registry = config.registry
    registry.registerUtility(mock_factory, interfaces.IClientFactory)
    request = testing.DummyRequest(registry=config.registry)
    assert auth.get_client(request, '9876') is None
    mock_factory.assert_called_with(request, '9876')
예제 #5
0
파일: auth_test.py 프로젝트: ningyifan/h
def test_get_client(config):
    client = MockClient(None, '4321')
    mock_factory = MagicMock()
    mock_factory.return_value = client
    registry = config.registry
    registry.registerUtility(mock_factory, interfaces.IClientFactory)
    request = testing.DummyRequest(registry=config.registry)
    assert auth.get_client(request, '4321') is client
    mock_factory.assert_called_with(request, '4321')
예제 #6
0
파일: auth_test.py 프로젝트: ningyifan/h
def test_get_client(config):
    client = MockClient(None, '4321')
    mock_factory = MagicMock()
    mock_factory.return_value = client
    registry = config.registry
    registry.registerUtility(mock_factory, interfaces.IClientFactory)
    request = testing.DummyRequest(registry=config.registry)
    assert auth.get_client(request, '4321') is client
    mock_factory.assert_called_with(request, '4321')
예제 #7
0
파일: auth_test.py 프로젝트: ningyifan/h
def test_get_client_bad_secret(config):
    client = MockClient(None, '9876')
    client.client_secret = 'scramble'
    mock_factory = MagicMock()
    mock_factory.return_value = client
    registry = config.registry
    registry.registerUtility(mock_factory, interfaces.IClientFactory)
    request = testing.DummyRequest(registry=config.registry)
    assert auth.get_client(request, '9876', client_secret='1234') is None
    mock_factory.assert_called_with(request, '9876')
예제 #8
0
파일: auth_test.py 프로젝트: ningyifan/h
def test_get_client_bad_secret(config):
    client = MockClient(None, '9876')
    client.client_secret = 'scramble'
    mock_factory = MagicMock()
    mock_factory.return_value = client
    registry = config.registry
    registry.registerUtility(mock_factory, interfaces.IClientFactory)
    request = testing.DummyRequest(registry=config.registry)
    assert auth.get_client(request, '9876', client_secret='1234') is None
    mock_factory.assert_called_with(request, '9876')
예제 #9
0
def token(args):
    """Generate an OAuth bearer token for the specified principal."""
    from h.auth import get_client, generate_signed_token

    if not args.config_uri.endswith('#api'):
        args.config_uri += '#api'

    paster.setup_logging(args.config_uri)
    env = paster.bootstrap(args.config_uri)
    request = env['request']
    registry = env['registry']

    request.client = get_client(request, registry.settings['h.client_id'])
    request.user = args.sub
    request.expires_in = args.ttl
    request.extra_credentials = {}

    token = generate_signed_token(request)

    print(token)
예제 #10
0
파일: script.py 프로젝트: bbarker/h
def token(args):
    """Generate an OAuth bearer token for the specified principal."""
    from h.auth import get_client, generate_signed_token

    if not args.config_uri.endswith('#api'):
        args.config_uri += '#api'

    paster.setup_logging(args.config_uri)
    env = paster.bootstrap(args.config_uri)
    request = env['request']
    registry = env['registry']

    request.client = get_client(request, registry.settings['h.client_id'])
    request.user = args.sub
    request.expires_in = args.ttl
    request.extra_credentials = {}

    token = generate_signed_token(request)

    print(token)