diff --git a/OAuth2.agent.lib.nut b/OAuth2.agent.lib.nut index a9fc030..9ae8607 100644 --- a/OAuth2.agent.lib.nut +++ b/OAuth2.agent.lib.nut @@ -40,7 +40,7 @@ enum Oauth2DeviceFlowState { // The class that introduces OAuth2 namespace class OAuth2 { - static VERSION = "2.0.0"; + static VERSION = "2.0.1"; } // The class that represents OAuth 2.0 authorization flow @@ -69,7 +69,7 @@ class OAuth2.JWTProfile { _expiresAt = 0; // Debug mode, records non-error events - _debug = true; + _debug = false; // Client constructor. // Parameters: @@ -159,7 +159,7 @@ class OAuth2.JWTProfile { crypto.sign(crypto.RSASSA_PKCS1_SHA256, header + "." + body, _decodePem(_jwtSignKey), function(err, sig) { if (err) { - server.error(err); + _error(err); return; } @@ -169,8 +169,8 @@ class OAuth2.JWTProfile { "assertion" : (header + "." + body + "." + signature) }); - server.log("Making a request to the host: " + _tokenHost); - server.log((header + "." + body + "." + signature)); + _log("Making a request to the host: " + _tokenHost); + _log((header + "." + body + "." + signature)); // Post, get the token local request = http.post(_tokenHost, {}, oauthreq); @@ -215,7 +215,7 @@ class OAuth2.JWTProfile { } else { // Error getting token local mess = "Error getting token: " + resp.statuscode + " " + resp.body; - client._error(mess); + client._log(mess); userCallback(null, mess); } } @@ -513,7 +513,7 @@ class OAuth2.DeviceFlow { local respData = http.jsondecode(resp.body); if (null != _extractPollData(respData)) { _reset(); - _error("Something went wrong during code request: " + resp.body); + _log("Something went wrong during code request: " + resp.body); cb(null, resp.body); return; } @@ -527,7 +527,7 @@ class OAuth2.DeviceFlow { } catch (error) { _reset(); local msg = "Provider data processing error: " + error; - _error(msg); + _log(msg); cb(null, msg); } } @@ -547,15 +547,15 @@ class OAuth2.DeviceFlow { local respData = http.jsondecode(resp.body); if (null != _extractToken(respData)) { _reset(); - _error("Something went wrong during refresh: " + resp.body); + _log("Something went wrong during refresh: " + resp.body); cb(null, resp.body); } else { cb(_accessToken, null); } } catch (error) { _reset(); - local msg = "Token refreshing error: " + error - _error(msg); + local msg = "Token refreshing error: " + error; + _log(msg); cb(null, msg); } } @@ -579,7 +579,7 @@ class OAuth2.DeviceFlow { if (date().time > _expiresAt) { _reset(); local msg = "Token acquiring timeout"; - _error(msg); + _log(msg); cb(null, msg); return msg; } @@ -642,14 +642,14 @@ class OAuth2.DeviceFlow { } } else { local msg = "Unexpected server response code:" + statusCode; - _error(msg); + _log(msg); _reset(); cb(null, msg); } } catch (error) { local msg = "General server poll error: " + error; _reset(); - _error(msg); + _log(msg); cb(null, msg); } } @@ -792,11 +792,6 @@ class OAuth2.DeviceFlow { } } - // Records error event - function _error(txt) { - server.error("[OAuth2DeviceFlow] " + txt); - } - // Records non-error event function _log(txt) { if (_debug) { diff --git a/README.md b/README.md index 148f547..b3739f4 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This library provides OAuth 2.0 authentication and authorization flows. It suppo The library exposes retrieved access tokens for applications and hides provider-specific operations, including the renewal of expired tokens. -**To add this library to your project, add** `#require "OAuth2.agent.lib.nut:2.0.0"` **to the top of your agent code.** +**To add this library to your project, add** `#require "OAuth2.agent.lib.nut:2.0.1"` **to the top of your agent code.** ## OAuth2.JWTProfile.Client ## @@ -38,7 +38,7 @@ The second parameter, *userSettings*, defines a table with user- and application ```squirrel // OAuth 2.0 library -#require "OAuth2.agent.lib.nut:2.0.0" +#require "OAuth2.agent.lib.nut:2.0.1" // Substitute with real values const GOOGLE_ISS = "rsalambda@quick-cacao-168121.iam.gserviceaccount.com"; @@ -113,7 +113,7 @@ if (token) { ### isTokenValid() ### -This method checks if the access token is valid by comparing its expiry time with current time. +This method checks if the access token is valid by comparing its expiry time with current time. #### Return Value #### @@ -128,7 +128,7 @@ server.log("The access token is " + (client.isTokenValid() ? "" : "in") + "valid ### Complete Example ### ```squirrel -#require "OAuth2.agent.lib.nut:2.0.0 +#require "OAuth2.agent.lib.nut:2.0.1 // Substitute with real values const GOOGLE_ISS = "rsalambda@quick-cacao-168121.iam.gserviceaccount.com"; @@ -232,7 +232,7 @@ The *notifyUserCallback* function should have the following parameters: #### Return Value #### -String — `null` in the case of success, or an error message if the client is already performing a request and the *force* directive is set. +String — `null` in the case of success, or an error message if the client is already performing a request and the *force* directive is set. #### Example #### @@ -305,7 +305,7 @@ server.log("The client is " + (client.isAuthorized() ? "" : "un") + "authorized ### refreshAccessToken(*tokenReadyCallback*) ### -This method asynchronously refreshes the access token and invokes the callback function when this has been completed or an error occurs. +This method asynchronously refreshes the access token and invokes the callback function when this has been completed or an error occurs. #### Parameters #### @@ -342,7 +342,7 @@ client.refreshAccessToken( ### Complete Example ### ```squirrel -#require "OAuth2.agent.lib.nut:2.0.0 +#require "OAuth2.agent.lib.nut:2.0.1 // Fill CLIENT_ID and CLIENT_SECRET with correct values local userConfig = { "clientId" : "", diff --git a/examples/DeviceFlowGoogle.agent.nut b/examples/DeviceFlowGoogle.agent.nut index 23685e3..7ea186f 100644 --- a/examples/DeviceFlowGoogle.agent.nut +++ b/examples/DeviceFlowGoogle.agent.nut @@ -22,7 +22,7 @@ // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. -#require "OAuth2.agent.lib.nut:2.0.0" +#require "OAuth2.agent.lib.nut:2.0.1" const CLIENT_ID = ""; const CLIENT_SECRET = ""; diff --git a/examples/JWTGooglePubSub.agent.nut b/examples/JWTGooglePubSub.agent.nut index a9393b3..b4e2716 100644 --- a/examples/JWTGooglePubSub.agent.nut +++ b/examples/JWTGooglePubSub.agent.nut @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. //@include "../OAuth2.agent.lib.nut" -#require "OAuth2.agent.lib.nut:2.0.0" +#require "OAuth2.agent.lib.nut:2.0.1" const GOOGLE_ISS = ""; const GOOGLE_SECRET_KEY = ""; diff --git a/tests/README.md b/tests/README.md index 61b6de1..242270b 100644 --- a/tests/README.md +++ b/tests/README.md @@ -2,7 +2,7 @@ ## Google JWT Profile Tests (PubSub Scope) ## -Follow the JWT example [instructions](examples#jwt-profile-for-oauth-20) to obtain the *GOOGLE_ISS* and *GOOGLE_SECRET_KEY* values and set them as the environment variables. +Follow the JWT example [instructions](../examples#jwt-profile-for-oauth-20) to obtain the *GOOGLE_ISS* and *GOOGLE_SECRET_KEY* values and set them as the environment variables. This test suite can be run automatically: @@ -12,7 +12,7 @@ impt test run --tests GooglePubSubJWTAuth.agent.test.nut:: ## Google Device Flow Tests ## -Follow the OAuth 2.0 Device Flow example [instructions](examples#oauth-20-device-flow) to obtain the *CLIENT_ID* and *CLIENT_SECRET* values and set them as the environment variables. +Follow the OAuth 2.0 Device Flow example [instructions](../examples#oauth-20-device-flow) to obtain the *CLIENT_ID* and *CLIENT_SECRET* values and set them as the environment variables. This test requires some manual interaction and can be run: