[GH-ISSUE #249] Google Drive example fails with missing state error #143

Closed
opened 2026-03-03 16:46:04 +03:00 by kerem · 4 comments
Owner

Originally created by @iby on GitHub (Jul 8, 2016).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/249

Using responseType = "token" works, but the original responseType = "code" fails with Missing state error. Need to use code type in order to get refresh token, base on the playground notes.

  • OS targeted (with version): 10.11
  • OAuth provider: Google Drive OAuth 2.0
  • OAuthSwift version: latest release
Originally created by @iby on GitHub (Jul 8, 2016). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/249 Using `responseType = "token"` works, but the original `responseType = "code"` fails with `Missing state` error. Need to use `code` type in order to get refresh token, base on the [playground](https://developers.google.com/oauthplayground/) notes. - **OS targeted (with version):** 10.11 - **OAuth provider:** Google Drive OAuth 2.0 - **OAuthSwift version:** latest release
kerem 2026-03-03 16:46:04 +03:00
Author
Owner

@phimage commented on GitHub (Jul 8, 2016):

maybe this could work by setting allowMissingStateCheck to true (if state missing)
let me know

<!-- gh-comment-id:231304816 --> @phimage commented on GitHub (Jul 8, 2016): maybe this could work by setting `allowMissingStateCheck` to true (if state missing) let me know
Author
Owner

@iby commented on GitHub (Jul 8, 2016):

Yep, it works, but refresh_token in credentials provided as an empty string. Any ideas why would that be?

<!-- gh-comment-id:231310291 --> @iby commented on GitHub (Jul 8, 2016): Yep, it works, but `refresh_token` in credentials provided as an empty string. Any ideas why would that be?
Author
Owner

@phimage commented on GitHub (Jul 8, 2016):

Did we pass in the code defined bellow in OAuthSwift2 (code which affect the refresh token

if let refreshToken = responseParameters["refresh_token"] as? String {
                self.client.credential.oauth_refresh_token = refreshToken.safeStringByRemovingPercentEncoding
            }
<!-- gh-comment-id:231314041 --> @phimage commented on GitHub (Jul 8, 2016): Did we pass in the code defined bellow in OAuthSwift2 (code which affect the refresh token ``` swift if let refreshToken = responseParameters["refresh_token"] as? String { self.client.credential.oauth_refresh_token = refreshToken.safeStringByRemovingPercentEncoding } ```
Author
Owner

@iby commented on GitHub (Jul 8, 2016):

Yes, there is that check in the code. Apparently must provide additional parameters approval_prompt=force&access_type=offline – they are used in the playground and access_type is reported to be the one that enforces refresh_token being sent with the response.

<!-- gh-comment-id:231324249 --> @iby commented on GitHub (Jul 8, 2016): Yes, there is that check in the code. Apparently must provide additional parameters `approval_prompt=force&access_type=offline` – they are used in the playground and `access_type` is reported to be the one that enforces `refresh_token` being sent with the response.
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#143
No description provided.