Device Authentication¶
When you connect to an IoTize device, your are an Anonymous user. You can access some public information depending on the device configuration.
To access more resources, you may have to login with a different profile.
Login¶
let result: Promise<boolean> = device.login("username", "password"); result .then(() => { // Login successful }) .catch((err) => { // An error occurred // Maybe device did not respond ? });
import com.iotize.android.device.device.api.AuthStateChangeCallback; // ... IoTizeDevice device = ...; device .login("myusername", "mypassword") .execute(new AuthStateChangeCallback() { @Override public void onNewAuthState(DeviceAuth.AuthState authState) { Log.d(TAG, "Now logged in with username " + authState.username); } @Override public void onAuthFailure(Throwable error) { Log.e(TAG, "Auth error " + error.getMessage(), error); } });
Logout¶
let result: Promise<boolean> = device.logout(); result .then(() => { // Logout successful }) .catch((err) => { // An error occurred // Maybe device did not respond ? });
import com.iotize.android.device.device.api.AuthStateChangeCallback; // ... IoTizeDevice device = ...; device .logout() .execute(new AuthStateChangeCallback() { @Override public void onNewAuthState(DeviceAuth.AuthState authState) { Log.d(TAG, "Now log out"); } @Override public void onAuthFailure(Throwable error) { Log.e(TAG, "Auth error " + error.getMessage(), error); } });