No Access Tokens Causing Apps to Fail [SOLVED]

iOS apps that worked 30 minutes ago are no longer working. The problem seems to be retrieving the access token. My Photons are still online and working, and I can call functions from the CLI, but not from my apps. If I call a function from my app, I get an “Invalid_token” error message. Also, I can’t list my access tokens, even though I know I have at least one which I can see in Build. This is the code I use to list them,

func listAccessTokens() {
        let url = NSURL(string: "https://api.particle.io/v1/access_tokens")
        let request = NSMutableURLRequest(URL: url!, cachePolicy: .ReloadIgnoringCacheData, timeoutInterval: 10)
        request.HTTPMethod = "GET"
        let userAndPassword = userName + ":" + password
        print("\(userName)  \(password)")
        let plainData = userAndPassword.dataUsingEncoding(NSUTF8StringEncoding)
        let base64String = plainData!.base64EncodedStringWithOptions(.Encoding64CharacterLineLength)
        request.setValue("Basic " + base64String, forHTTPHeaderField: "Authorization")
        
        session = NSURLSession.sharedSession()
        
        let dataTask = session.dataTaskWithRequest(request) { (data, response, taskError) -> Void in
            if (taskError == nil) {
                do {
                    if let tokenArray = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments) as? NSArray {
                        print(tokenArray)
                    }else{
                        print("tokenArray was nil")
                    }
                } catch let jsonError as NSError {
                    print(jsonError.localizedDescription)
                }
            }else{
                print("taskError from executeFunction func is: \(taskError!.localizedDescription)")
            }
        }
        dataTask.resume()
}

The result of calling this function is “tokenArray was nil”. This code worked fine last night, and for many months before; it hasn’t been changed recently. If I put in a statement to print out the data (after converting it to a string) before doing the JSON deserialization, then I get this output:

data string is: {
“ok”: false,
“errors”: [
{}
]
}

@ido, @jgoggins any thoughts?

After Edit: I also tried to retrieve my access tokens using the CLI, using “particle token list” (btw, is this documented anywhere? I got it from the forum). The results of that look similar to what I get with my app,

RDM-iMac:~ ricdelmar$ particle token list
Checking with the cloud…
? Using account rdelmar@comcast.net
Please enter your password: *************
error listing tokens: [object Object]
Error listing access tokens [ {} ]
Please make sure you’re online and logged in.
[ {} ]

Hey @ido, are you able to help with this?

So, far, I’m getting no response to my question. Do you know who else I should ping? Since I can’t get my access tokens from my apps or from the CLI, it seems there must be some problem at Particle, or with my account. None of my apps are currently working, so I would like to get this fixed as soon as possible.

1 Like

Hi @Ric,

I’m sorry about the slow response. Our team deployed some code yesterday, and this appears to have introduced the bug you hit. They’re deploying some different updates today, and I’ve asked them to fix this asap.

If all else fails, @KyleG feel free to ping me :slight_smile:

Thanks,
David

2 Likes

Thanks David, it appears the problem has now been fixed.

Hi @Ric,

Glad it’s working for you again, one of our engineers deployed a fix about an hour ago. :slight_smile:

Thanks,
David

Ric I’m glad its working for you again. If you ever run into anymore problems in the future feel free to ping me and I will do my best to get it solved for you.
Thanks,
Kyle

I’m experiencing the same issue via the particle cli command line:

D:\Downloads>particle token list
Checking with the cloud…
? Using account xyz@zyz.com
Please enter your password: *******
error listing tokens: [object Object]
Error listing access tokens [ { code: 401 } ]
Please make sure you’re online and logged in.
[ { code: 401 } ]

yes I can do this immediately afterwards:

D:\Downloads>particle token new
? Using account xyz@zyx.com
Please enter your password: *******
New access token expires on Thu Jun 22 2017 18:03:53 GMT-0400 (Eastern Daylight Time)

@Dave

Hi @Lcstyle,

What version of the CLI are you using at the moment?

particle --version

I just tested this, and it worked for me, I’m using version 1.20.1.

Thanks,
David

D:\Downloads>particle --version
1.20.1

i just checked again , no worky :frowning:

so 401 means unauthorized, so I’m guessing you’re not typing your password properly?

that’s why I followed up in my comment above with the above. I can also run curl https://api.particle.io/v1/access_tokens -u username@xyz.com:samepassword and view the access tokens.

How about

particle logout
particle login
particle token list

Don’t revoce the acces token on logout

Does this change anything?

If you are on Windows and have additional keyboard layouts installed, make sure you use the correct one.
Windows has the “awesome” :stuck_out_tongue_winking_eye: feature to allow individual keyboard layouts per application and since you won’t see your acutal password on screen, you might type the wrong letters (happens to me regularly with English vs. German :blush:)

For the record I’d like to reiterate, I only have one account, and I am using the same password for it, it has not changed. I am not typing in the wrong password here guys, though I do understand that it does look that way. I am logging in successfully in the same command prompt and typing the exact same password for all the commands. Some of the commands that prompt for password work (actually particle list tokens is the only one so far that I’ve tried that didn’t). As far as keyboard layouts are concerned I understand how that could come into play here, but I do not use keyboard layouts whatsoever.

OK so I did try the following steps:
partice cli logout (do not revoke access token)
particle login (successfully completely login)

New Behavior:
particle list tokens (no longer returns 401, but also does not return any output, just a blank new line)

So then I tried going back and issuing this command:

C:\Users\lcstyle>particle logout
? Would you like to revoke the current authentication token? Yes
? Please enter your password *******
There was an error revoking the token [ ‘Bad credentials or unknown token’ ]

AHA, bad credentials OR UNKNOWN TOKEN.

So Again, I think what’s happening here is that there’s a stuck (old or revoked) access token in the particle cli configuration.

I went ahead and logged back in as normal, and I get the same new behavior “particle list tokens” now returns an empty result set. I think the old paradigm was that you had to include an access token in your request to the access_tokens api endpoint, but as you can see with my previous curl command, that’s no longer required. Maybe particle cli hasn’t been updated to reflect this change?

You can see this for yourself in the documentation, it clearly states that for the list access tokens endpoint the format is as follows (note the inclusion of an access token):

curl https://api.particle.io/v1/access_tokens?access_token=xyz -u username:password

but you can run this command and it will work:

curl https://api.particle.io/v1/access_tokens -u username:password

Well, the command doesn’t look correct. It should be this:

KENMBP:~ kennethlimcp$ p token list
Checking with the cloud...
? Using account iloveparticle@particle.elite
Please enter your password: *******

particle token list
Checking with the cloud…
? Using account user@domain.com
Please enter your password: *******
error listing tokens: [object Object]
Error listing access tokens [ { code: 401 } ]
Please make sure you’re online and logged in.
[ { code: 401 } ]

looks like the new behavior (return of empty lines) was due to me transposing the command arguments (list and token), the error above is still the error I am receiving.

No idea what’s wrong with your account then.

Maybe @dave can help to check.

@Lcstyle, so, is the command working for you or not?

2 Likes

looks like the new behavior (return of empty lines) was due to me transposing the command arguments (list and token), the error above is still the error I am receiving. (401) when issuing particle token list. Sorry for any confusion this may have caused (mea culpa).

1 Like