Skip to content

Device Authentication

When you connect to an IoTize device, your are considered as an Anonymous user. You can access some public informations 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 occured
        // Maybe device did not responded ?
    });
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 occured
        // Maybe device did not responded ?
    });
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);
        }
    });