Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return user id when creating auth token #4088

Merged
merged 3 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/development/journalist_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ This will produce a response with your Authorization token:

{
"expiration": "2018-07-10T04:29:41.696321Z",
"token": "eyJhbGciOiJIUzI1NiIsImV4cCI6MTUzMTE5Njk4MSwiaWF0IjoxNTMxMTY4MTgxfQ.eyJpZCI6MX0.TBSvfrICMxtvWgpVZzqTl6wHYNQuGPOaZpuAKwwIXXo"
"token": "eyJhbGciOiJIUzI1NiIsImV4cCI6MTUzMTE5Njk4MSwiaWF0IjoxNTMxMTY4MTgxfQ.eyJpZCI6MX0.TBSvfrICMxtvWgpVZzqTl6wHYNQuGPOaZpuAKwwIXXo",
"journalist_uuid": "54d81dae-9d94-4145-8a57-4c804a04cfe0"
}

Thereafter in order to authenticate to protected endpoints, send the token in
Expand Down
9 changes: 6 additions & 3 deletions securedrop/journalist_app/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ def get_token():
journalist = Journalist.login(username, passphrase, one_time_code)
token_expiry = datetime.utcnow() + timedelta(
seconds=TOKEN_EXPIRATION_MINS * 60)
response = jsonify({'token': journalist.generate_api_token(
expiration=TOKEN_EXPIRATION_MINS * 60),
'expiration': token_expiry.isoformat() + 'Z'})

response = jsonify({
'token': journalist.generate_api_token(expiration=TOKEN_EXPIRATION_MINS * 60),
'expiration': token_expiry.isoformat() + 'Z',
'journalist_uuid': journalist.uuid,
})

# Update access metadata
journalist.last_access = datetime.utcnow()
Expand Down
3 changes: 2 additions & 1 deletion securedrop/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ def test_journo(journalist_app):
'username': username,
'password': password,
'otp_secret': otp_secret,
'id': user.id}
'id': user.id,
'uuid': user.uuid}


@pytest.fixture(scope='function')
Expand Down
1 change: 1 addition & 0 deletions securedrop/tests/test_journalist_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_valid_user_can_get_an_api_token(journalist_app, test_journo):
headers=get_api_headers())
observed_response = json.loads(response.data)

assert observed_response['journalist_uuid'] == test_journo['uuid']
assert isinstance(Journalist.validate_api_token_and_get_user(
observed_response['token']), Journalist) is True
assert response.status_code == 200
Expand Down