Skip to content

Commit 89f31b4

Browse files
Hieu Lam - TMAcweitat
andauthored
feature-8975: API to verify password of signed in account (#9008)
* feature-8975: API to verify password of signed in account * feature-8975: API to verify password of signed in account * feature-8975: API to verify password of signed in account * feature-8975: API to verify password of signed in account * feature-8975: API to verify password of signed in account * feature-8975: API to verify password of signed in account * feature-8975: API to verify password of signed in account * feature-8975: API to verify password of signed in account --------- Co-authored-by: cweitat <[email protected]>
1 parent 3a85e5e commit 89f31b4

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

app/api/auth.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,3 +466,30 @@ def decorated(*args, **kwargs):
466466
def environment_details():
467467
envdump = EnvironmentDump(include_config=False)
468468
return envdump.dump_environment()
469+
470+
471+
@auth_routes.route('/verify-password', methods=['POST'])
472+
@jwt_required
473+
def verify_password():
474+
data = request.get_json()
475+
password = data.get('password')
476+
477+
if not all([current_user.id, password]):
478+
logging.error('user or password missing')
479+
return jsonify(error='user or password missing'), 400
480+
481+
try:
482+
user = User.query.filter_by(id=current_user.id).one()
483+
except NoResultFound:
484+
logging.info('User Not Found')
485+
raise NotFoundError({'source': ''}, 'User Not Found')
486+
487+
result = False
488+
if user.is_correct_password(password):
489+
result = True
490+
491+
return jsonify(
492+
{
493+
"result": result,
494+
}
495+
)

docs/api/blueprint/auth/authentication.apib

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,33 @@ For mobile clients, dealing with cookies is not easy, and traditional problem of
105105
"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NjQ4NTQyODIsIm5iZiI6MTU2NDg1NDI4MiwianRpIjoiZGM2MjU3MjMtZjYyMi00YmYzLTgxMGQtYTVmZTljMWNhMDIyIiwiZXhwIjoxNTY0OTQwNjgyLCJpZGVudGl0eSI6MSwiZnJlc2giOnRydWUsInR5cGUiOiJhY2Nlc3MiLCJjc3JmIjoiMDFkNDI2MmYtOGRiZS00MWEwLWI2OWUtODY1M2QzNTRkYTUyIn0.lscegFJqTeqsfpqBNC6t2E2_A38JYqriQh5wixQQOtU"
106106
}
107107

108+
## API to verify password of signed in account [/v1/auth/verify-password]
109+
110+
### API to verify password of signed in account [POST]
111+
112+
API to verify password of signed in account using JWT token
113+
114+
+ Request
115+
116+
+ Headers
117+
118+
Content-Type: application/vnd.api+json
119+
120+
Authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NjQ4NTQyODIsIm5iZiI6MTU2NDg1NDI4MiwianRpIjoiZGM2MjU3MjMtZjYyMi00YmYzLTgxMGQtYTVmZTljMWNhMDIyIiwiZXhwIjoxNTY0OTQwNjgyLCJpZGVudGl0eSI6MSwiZnJlc2giOnRydWUsInR5cGUiOiJhY2Nlc3MiLCJjc3JmIjoiMDFkNDI2MmYtOGRiZS00MWEwLWI2OWUtODY1M2QzNTRkYTUyIn0.lscegFJqTeqsfpqBNC6t2E2_A38JYqriQh5wixQQOtU
121+
122+
+ Body
123+
124+
{
125+
"password": "password"
126+
}
127+
128+
+ Response 200 (application/json)
129+
130+
{
131+
"result": true
132+
}
133+
134+
108135
## Token Refresh [/v1/auth/token/refresh]
109136

110137
**Note**: The access token generated by this method is not fresh. Which means it is good for all auth except sensitive APIs like changing password and changing email. This is done to increase security and prevent damage if a refresh token is leaked.

tests/all/integration/api/helpers/test_auth.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,18 @@ def test_get_user_id(client, jwt):
5656

5757
assert response.status_code == 200
5858
assert json.loads(response.data)['user_id']
59+
60+
61+
def test_verify_password(client, jwt):
62+
"""Method to test verify password"""
63+
data = json.dumps({'password': 'password'})
64+
65+
response = client.post(
66+
'/v1/auth/verify-password',
67+
content_type='application/vnd.api+json',
68+
headers=jwt,
69+
data=data,
70+
)
71+
72+
assert response.status_code == 200
73+
assert json.loads(response.data)['result']

0 commit comments

Comments
 (0)