Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

invalid_token error using auth0 access token

I am using auth0 to authenticate fitbit in swift. I am able to get the access_token and id_token and user profile info using auth0 api. But when I make request to fitbit api I get an error stating invalid token. Please Help!!

Best Answer
3 REPLIES 3

We can't debug your application, but if you share the HTTP request that your app is actually making and the response, we can help identify the issue. You can use a tool like Runscope Traffic Inspector.

Best Answer
0 Votes

I am getting this error:

 

{

    errors =     (

                {

            errorType = "invalid_token";

            message = "Access token invalid: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL215Zml0YXBwLmF1dGgwLmNvbS8iLCJzdWIiOiJmaXRiaXR8NDI5TlBHIiwiYXVkIjoiTkRzZ2pZRGZNUFd3d2M1MTNPbTREcUdXS2FDOTNHZDIiLCJleHAiOjE0NTc3MTgyNTMsImlhdCI6MTQ1NzY4MjI1M30.7hR0r24Ztq9wiIr_y2SSQhyFkhDs1g0Rj-8SkNGytm8. Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process.";

        }

    );

    success = 0;

}

 

The request I am making is:

 

let targetURLString = "https://api.fitbit.com/1/user/-/profile.json"

let request = NSMutableURLRequest(URL: NSURL(string: targetURLString)!)

request.HTTPMethod = "GET"

request.setValue("Bearer \(idToken!)", forHTTPHeaderField: "Authorization")

 

let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration())

 

let task: NSURLSessionDataTask = session.dataTaskWithRequest(request) { (data, response, error) -> Void in

            do{

                let dat = try NSJSONSerialization.JSONObjectWithData(data!, options:   NSJSONReadingOptions.MutableContainers) as! NSDictionary

                NSUserDefaults.standardUserDefaults().setObject(dat, forKey: "dataDictionary")

                NSUserDefaults.standardUserDefaults().synchronize()

                

                print(dat)

            }

            catch{

                print("Could not convert JSON data into a dictionary.")

            }

        }

        task.resume()

 

Best Answer
0 Votes

Im having the exact same error using Auth0. Were you able to find a solution?

Best Answer
0 Votes