Skip to content

Commit

Permalink
Adding initial authentication method and token store. @Version 0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
timcrider committed May 2, 2023
1 parent 033f31a commit f810e43
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"dotenv-expand": "^10.0.0"
},
"name": "@timcrider/aquasec-client",
"version": "0.0.3",
"version": "0.0.4",
"main": "index.js",
"directories": {
"test": "tests"
Expand Down
19 changes: 19 additions & 0 deletions src/aqua-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,25 @@ class AquaClient {

return url.toString();
}

fetchToken(credentials) {
return this.request({method: 'POST', endpoint: '/api/v1/login', body: credentials.fetch()});
}

authenticate(credentials) {
return new Promise (async (resolve, reject) => {
try {
let token = await this.fetchToken(credentials);
this.setToken(token.token);

// @todo check options to reutrn token or true
resolve(token);
} catch (err) {
reject(err);
}
});
}

}

module.exports = AquaClient;

0 comments on commit f810e43

Please sign in to comment.