Skip to content

Commit 1a95872

Browse files
committed
Add authentication wrapper
1 parent 6157255 commit 1a95872

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/index.js

+20
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,26 @@ class NetatmoClient {
7373
this.expiresInTimestamp = 0
7474
}
7575

76+
/**
77+
* Authenticate with access token, refresh token or client credentials
78+
*
79+
* @param {string} accessToken Access token for your user
80+
* @param {string} refreshToken Refresh token to get a new access token
81+
* @param {number} expiresInTimestamp Validity timelaps as timestamp
82+
* @param {string} username User address email
83+
* @param {string} password User password
84+
* @return {Token} Token `{accessToken, refreshToken, expiresInTimestamp}`
85+
*/
86+
async authenticate (accessToken = null, refreshToken = null, expiresInTimestamp = 0, username = null, password = null) {
87+
if (this.checkAndSetAccesToken(accessToken, expiresInTimestamp)) {
88+
return new Token(accessToken, refreshToken, expiresInTimestamp)
89+
}
90+
if (refreshToken) {
91+
return this.authenticateByRefreshToken(refreshToken)
92+
}
93+
return this.authenticateByClientCredentials(username, password)
94+
}
95+
7696
/**
7797
* Return url for authorize code grant
7898
*

0 commit comments

Comments
 (0)