[GH-ISSUE #176] Scope with space symbol doesn't create NSURL #103

Closed
opened 2026-03-03 16:45:42 +03:00 by kerem · 4 comments
Owner

Originally created by @leo150 on GitHub (Jan 22, 2016).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/176

Let's say we need to login into fitbit account with profile and weight scopes. From docs scope field is:

space-delimited list of the permissions you are requesting

But when we call authorizeWithCallbackURL with scope string "profile weight" than this part of code silently skips our url:
if let queryURL = NSURL(string: urlString) { self.authorize_url_handler.handle(queryURL) }
It would be nice to add some log message or replace all space delimiters in urlString

Originally created by @leo150 on GitHub (Jan 22, 2016). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/176 Let's say we need to login into fitbit account with `profile` and `weight` scopes. From docs `scope` field is: > space-delimited list of the permissions you are requesting But when we call `authorizeWithCallbackURL` with scope string "profile weight" than this part of code silently skips our url: `if let queryURL = NSURL(string: urlString) { self.authorize_url_handler.handle(queryURL) }` It would be nice to add some log message or replace all space delimiters in `urlString`
kerem closed this issue 2026-03-03 16:45:42 +03:00
Author
Owner

@leo150 commented on GitHub (Jan 22, 2016):

Duplicate of #156

<!-- gh-comment-id:173958093 --> @leo150 commented on GitHub (Jan 22, 2016): Duplicate of #156
Author
Owner

@phimage commented on GitHub (Jan 22, 2016):

I think this is not a duplicate

I will call failure callback in this case
Scope must be encoded here
workaround for now, html encode yourself the scope, I think replace space with %20

<!-- gh-comment-id:173958935 --> @phimage commented on GitHub (Jan 22, 2016): I think this is not a duplicate I will call failure callback in this case Scope must be encoded here workaround for now, html encode yourself the scope, I think replace space with %20
Author
Owner

@leo150 commented on GitHub (Jan 22, 2016):

@phimage, thanks for support!

Small sample of replacement if anyone needs:

    if let utf8String = urlString
        .stringByAddingPercentEncodingWithAllowedCharacters(
        NSCharacterSet.URLQueryAllowedCharacterSet()) {
            if let queryURL = NSURL(string: utf8String) {
                self.authorize_url_handler.handle(queryURL)
            }
        }
<!-- gh-comment-id:173968092 --> @leo150 commented on GitHub (Jan 22, 2016): @phimage, thanks for support! Small sample of replacement if anyone needs: ``` if let utf8String = urlString .stringByAddingPercentEncodingWithAllowedCharacters( NSCharacterSet.URLQueryAllowedCharacterSet()) { if let queryURL = NSURL(string: utf8String) { self.authorize_url_handler.handle(queryURL) } } ```
Author
Owner

@phimage commented on GitHub (Feb 9, 2016):

I just encode the query, not the full URL because of NSCharacterSet.URLQueryAllowedCharacterSet()

Also if there is problem to create te URL, failure callback will be called

<!-- gh-comment-id:181841896 --> @phimage commented on GitHub (Feb 9, 2016): I just encode the query, not the full URL because of `NSCharacterSet.URLQueryAllowedCharacterSet()` Also if there is problem to create te URL, failure callback will be called
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#103
No description provided.