Two legged authentication Android SDK

Hello, I would like to clarify me how to use the Android SDK (cloud and setup) when it is implementing “two leggued authentication”. I have my own backend (using OAuth credentials of a client) to create and store customers access token. All this following the guide

Now I’m building the mobile application using the SDK. The login of the mobile application is made against my own server. Once the client is logged the idea is to use the SDK for capturing variables, call functions and configure devices. Reading the documentation you need to create the strings which specifies “oauth_client_id”, “oauth_client_secret”, “organization_slug” and “product_slug” but How I can log into the Particle cloud with the SDK? I ask this because the method requires password eg particleCloud.logIn ("", “l33tp4ssw0rd”);. When the customer is created in this type of authentication is not created with password:

curl -X POST -u “xx:xx” -d -d no_password=true

I think I’m misinterpreting something?
Thank you for your help

1 Like

It looks like there’s a particleCloud.setAccessToken(tokenString, expirationDate) method that will log the customer in with the access token you have created.

Thanks for answering

Even when using the method setAccessToken with a valid token if I invoke the setup library sends me to the login activity.

Any ideas?

@ruframapi if you’re still getting the login activity even after calling setAccessToken(), that’s a bug. I’m going to be refactoring some of this code very soon, so it should be fixed in the next couple weeks.

Here’s the github bug I’ve filed for this:

Thank you, it is very important for us to use the Device Setup with 2-legged authentication. I wish you a happy coding .

Hey guys,

I’m running into the same problem… basically trying to figure out how to integrate two-leg authentication within an android app.

Can anyone shed some light on where I would even include the particleCloud.setAccessToken() function in relation to the sample apps (either SDK or Setup)?

Sorry if my question is too beginner but I’m just trying to figure out where to even get started with this. Any more insight into understanding the flow of the applications would be great


@reado You can call ParticleCloud.setAccessToken() right after you initialize the SDK.

I’m working on a few TODOs for Electron setup right now, but after those are done I’m going to be working on auth issues, including a brief addition to the docs on how to integrate 2-leg auth. Thanks for your patience, everyone.

I just tried this and I wasn’t able to reproduce it. Can anyone here try cloning the cloud SDK repo and trying the example app?

Once you have the example app building, open up LoginActivity, comment out the logIn() call, and replace it with this:

// the date below is arbitrary.  you can copy & paste it into the example code
// without worrying about your actual token expiration date
sparkCloud.setAccessToken("YOUR ACCESS TOKEN HERE", new Date(1461456951753L)); 

…and then try whatever SDK calls you want to make after that, and see what you get?


@reado @ruframapi could either of you try to repro with the steps I gave above? Thanks!

@jensck As you said I did and added below code before button listener

ParticleCloud particleCloud = ParticleCloud.get(this); particleCloud.setAccessToken("ACCESS_TOKEN", new Date(1461456951753L)); System.out.println("Is loggedIn:" + particleCloud.isLoggedIn());

And it returned me false

So I’m able to get the login working, but getting the claiming code is failing.

Below is in my Activity to start device setup.

        Responses.LogInResponse response = null;
        try {
            response = new Responses.LogInResponse(
        } catch (JSONException e) {

        ParticleAccessToken accessToken = ParticleAccessToken.fromNewSession(response);
        ParticleUser particleUser = ParticleUser.fromNewCredentials(mUserEmail, "placeholder");


Here’s the failure I’m getting:

E/Async: Error calling API: activation code was empty
    at android.os.AsyncTask$
    at java.util.concurrent.ThreadPoolExecutor.runWorker(
    at java.util.concurrent.ThreadPoolExecutor$

Found the error.

I had the device set for private which requires a user code.

Also, it only works the second time the app is loaded. The ParticleUser.fromNewCredentials saves the user but does not update the user (odd).

We need a particleCloud.setUser(...) function.

@jensck – just created a pull request to add a setUser function

Sorry for the delay on this – I’ve had a couple urgent issues come up that I had to address first. I’ll be working on this tonight and will offer an update then.

Sorry Jensck for the delay answer, I was outside of my country.

I have the same issue reported by brandongoode, the claiming process fail.

Hi jensck

There is some progress on this issue?,