Authentication help

i have a small app for personal use only and it started not being able to connect to the particle cloud.

I have been using the following to authenticate (used to work flawlessly)

Async.executeAsync(ParticleCloudSDK.getCloud(), new Async.ApiWork<ParticleCloud, Object>() {
           public Object callApi(ParticleCloud particleCloud) throws ParticleCloudException, IOException {
               mCloud = particleCloud;
               mDevice = particleCloud.getDevice(DeviceID);
               return -1;

            public void onSuccess(Object value) {
               loggedin = true;
               Toaster.s(MainActivity.this, "Logged in");

            public void onFailure(ParticleCloudException e) {
               Toaster.l(MainActivity.this, "Wrong credentials or no internet connectivity, please try again");

i also tried creating a Simple Auth Client and added

    <string name="oauth_client_id">id</string>
    <string name="oauth_client_secret">secret</string>

but I still get failure to connect. I am probably overlooking something very simple any help would be greatly appreciated.

so i just realized that if i turn off Two-step authentication everything works again. is there anyway to keep Two-step authentication turned on but still access the devices via an app?

Hi, two-step auth returns very specific error when trying to connect. There will be "error" property in response, that will have value of "mfa_required". The response will also have "mfa_token" property. After you get this error, You will need to hit (NSURLSessionDataTask *)loginWithUser:(NSString *)user mfaToken:(NSString *)mfaToken OTPToken:(NSString *)otpToken completion:(nullable ParticleCompletionBlock)completion endpoint and provide username, mfatoken from previous response and one-time-password generated by authenticator app to proceed. If all params are correct, this will grant you access token (same response structure as if it was for original login request on account with no two-step auth enabled).

Hope this helps.

1 Like