[GH-ISSUE #550] Fitbit expired token not handled #365

Closed
opened 2026-03-03 16:48:06 +03:00 by kerem · 0 comments
Owner

Originally created by @ivarunpatel on GitHub (Oct 3, 2019).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/550

Description:

Fitbit expired token not handled

            if let errors = jsonDic["errors"] as? [[String: AnyObject]] {
                for error in errors {
                    if let errorType = error["errorType"] as? String, errorType == "invalid_token" {
                        return true
                    }
                }
            }

Expire token response:

Error Domain=NSURLErrorDomain Code=401 "" 
UserInfo={Response-Body={"errors":[{"errorType":"expired_token","message":"Access token invalid: MY Token. Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process."}],"success":false}, 
NSErrorFailingURLKey=https://api.fitbit.com/1/user/-/activities/date/\2019-10-03.json, 

Response-Headers={
    "Content-Length" = 423;
    "Content-Type" = "application/json;charset=utf-8";
    Date = "Thu, 14 Dec 2017 09:47:03 GMT";
    Server = "cloudflare-nginx";
    "Www-Authenticate" = "Bearer realm=\"api.fitbit.com\"";
    "cf-ray" = "3cd03d4c8b11889c-BOM";
    "x-frame-options" = SAMEORIGIN;
}, OAuthSwiftError.response=<NSHTTPURLResponse: 0x1c4822260> { URL: https://api.fitbit.com/1/user/-/activities/date/\2019-10-03.json } { Status Code: 401, Headers {
    "Content-Length" =     (
        423
    );
    "Content-Type" =     (
        "application/json;charset=utf-8"
    );
    Date =     (
        "Thu, 14 Dec 2017 09:47:03 GMT"
    );
    Server =     (
        "cloudflare-nginx"
    );
    "Www-Authenticate" =     (
        "Bearer realm=\"api.fitbit.com\""
    );
    "cf-ray" =     (
        "3cd03d4c8b11889c-BOM"
    );
    "x-frame-options" =     (
        SAMEORIGIN
    );
} }, OAuthSwiftError.response.data=data, NSLocalizedDescription=}

Here,

key expired_token is not handled.

{"errors":[{"errorType":"expired_token","message":"Access token invalid: MY Token. Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process."}],"success":false}

Error handling code should be replaced with below code:

                if let errors = jsonDic["errors"] as? [[String: AnyObject]] {
                    for error in errors {
                        if let errorType = error["errorType"] as? String, errorType == "invalid_token" || errorType == "expired_token" {
                            return true
                        }
                    }
                }

OAuth Provider? (Twitter, Github, ..):

FitBit

OAuth Version:

  • Version 2

OS (Please fill the version) :

  • [] iOS :

Installation method:

  • [] CocoaPods

Library version:

  • [] v2.0.0

Xcode version:

  • [] 10.x (Swift 5.0)
Originally created by @ivarunpatel on GitHub (Oct 3, 2019). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/550 ### Description: Fitbit expired token not handled if let errors = jsonDic["errors"] as? [[String: AnyObject]] { for error in errors { if let errorType = error["errorType"] as? String, errorType == "invalid_token" { return true } } } **Expire token response:** ``` Error Domain=NSURLErrorDomain Code=401 "" UserInfo={Response-Body={"errors":[{"errorType":"expired_token","message":"Access token invalid: MY Token. Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process."}],"success":false}, NSErrorFailingURLKey=https://api.fitbit.com/1/user/-/activities/date/\2019-10-03.json, Response-Headers={ "Content-Length" = 423; "Content-Type" = "application/json;charset=utf-8"; Date = "Thu, 14 Dec 2017 09:47:03 GMT"; Server = "cloudflare-nginx"; "Www-Authenticate" = "Bearer realm=\"api.fitbit.com\""; "cf-ray" = "3cd03d4c8b11889c-BOM"; "x-frame-options" = SAMEORIGIN; }, OAuthSwiftError.response=<NSHTTPURLResponse: 0x1c4822260> { URL: https://api.fitbit.com/1/user/-/activities/date/\2019-10-03.json } { Status Code: 401, Headers { "Content-Length" = ( 423 ); "Content-Type" = ( "application/json;charset=utf-8" ); Date = ( "Thu, 14 Dec 2017 09:47:03 GMT" ); Server = ( "cloudflare-nginx" ); "Www-Authenticate" = ( "Bearer realm=\"api.fitbit.com\"" ); "cf-ray" = ( "3cd03d4c8b11889c-BOM" ); "x-frame-options" = ( SAMEORIGIN ); } }, OAuthSwiftError.response.data=data, NSLocalizedDescription=} ``` Here, key **expired_token** is not handled. {"errors":[{"errorType":"expired_token","message":"Access token invalid: MY Token. Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process."}],"success":false} Error handling code should be replaced with below code: ``` if let errors = jsonDic["errors"] as? [[String: AnyObject]] { for error in errors { if let errorType = error["errorType"] as? String, errorType == "invalid_token" || errorType == "expired_token" { return true } } } ``` ### OAuth Provider? (Twitter, Github, ..): FitBit ### OAuth Version: - [ ] Version 2 ### OS (Please fill the version) : - [] iOS : ### Installation method: - [] CocoaPods ### Library version: - [] v2.0.0 ### Xcode version: - [] 10.x (Swift 5.0)
kerem closed this issue 2026-03-03 16:48:06 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#365
No description provided.