Skip to content
This repository has been archived by the owner on Mar 10, 2023. It is now read-only.

Commit

Permalink
Merge pull request #19 from ScilifelabDataCentre/develop
Browse files Browse the repository at this point in the history
Bugfix for key login
  • Loading branch information
talavis authored May 14, 2020
2 parents 9f74405 + db77857 commit 0132d27
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
1 change: 1 addition & 0 deletions backend/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def add_order(): # pylint: disable=too-many-branches
try:
indata = flask.json.loads(flask.request.data)
except json.decoder.JSONDecodeError:
logging.debug('Bad json')
flask.abort(status=400)

validation = utils.basic_check_indata(indata, order, ['_id'])
Expand Down
12 changes: 6 additions & 6 deletions backend/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ def oidc_login():


# requests
@blueprint.route('/login/apikey', methods=['POST'])
@blueprint.route('/login/apikey/', methods=['POST'])
def key_login():
"""Log in using an apikey."""
try:
indata = flask.json.loads(flask.request.data)
except json.decoder.JSONDecodeError:
flask.abort(status=400)

if not 'api-username' in indata or not 'api-key' in indata:
if not 'api-user' in indata or not 'api-key' in indata:
logging.debug('API key login - bad keys: %s', indata)
return flask.Response(status=400)
if not utils.verify_api_key(indata['api-username'], indata['api-key']):
return flask.Response(status=401)
do_login(auth_id=indata['api-username'])
utils.verify_api_key(indata['api-user'], indata['api-key'])
do_login(auth_id=indata['api-user'])
return flask.Response(status=200)


Expand Down Expand Up @@ -114,7 +114,7 @@ def get_current_user_info():
return flask.jsonify({'user': outstructure})

# requests
@blueprint.route('/me/apikey')
@blueprint.route('/me/apikey/')
@login_required
def get_new_api_key():
"""
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/components/LoginPageKey.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
name="USERNAME"
type="text"
placeholder="username"
v-model="loginInfo.apiUsername"/>
v-model="loginInfo.apiUser"/>
</div>
<div class="field">
<input id="apikey"
Expand All @@ -31,15 +31,17 @@ export default {
data () {
return {
loginInfo: {
'apiUsername': '',
'apiUser': '',
'apiKey': '',
},
}
},
methods: {
submitLogin(event) {
event.preventDefault();
this.$store.dispatch('loginKey', this.loginInfo)
let loginData = {'api-key': this.loginInfo.apiKey,
'api-user': this.loginInfo.apiUser}
this.$store.dispatch('loginKey', loginData)
.then((response) => {
// add performed
let uuid = '';
Expand Down
7 changes: 2 additions & 5 deletions frontend/src/store/modules/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ const actions = {

loginKey (context, payload) {
return new Promise((resolve, reject) => {
let loginData = {};
loginData['api-username'] = payload.apiUsername;
loginData['api-key'] = payload.apiKey;
axios
.post('/api/user/login/apikey',
loginData,
.post('/api/user/login/apikey/',
payload,
{
headers: getCsrfHeader(),
})
Expand Down

0 comments on commit 0132d27

Please sign in to comment.