[GH-ISSUE #250] App doesn't seem to callback after authentication #142

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

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

So basically i'm having issues with the authentication side of things with the soundcloud api, so i'm using a webview which is programatically created and attaching this to the same view which works perfectly.

The issue is once i try to authenticate using one of the options from soundcloud either Facebook, Gmail the screen is just blank and it doesn't seem to be authenticating when using the connect with Facebook or gmail the reason why i say it isn't authenticating is because nothing is being logged in the console... and the email screen seems to be stuck as you can see in the image below... There's no callback once the authentication is done and this does work since there is output in the console when i'm testing the data being returned.

simulator screen shot 8 jul 2016 11 00 28

So this is the code i'm using to authenticate the user and save the users data below.

` func doOAuthSoundCloud(consumerKey: String, consumerSecret: String) {

    let oauthswift = OAuth2Swift(
        consumerKey:    consumerKey,
        consumerSecret: consumerSecret,
        authorizeUrl:   authorizeUrl,
        accessTokenUrl: accessToken,
        responseType:   "code"
    )

    oauthswift.authorize_url_handler = AuthWebViewController()

    let state: String = generateStateWithLength(20) as String
    oauthswift.authorizeWithCallbackURL( NSURL(string: "oauthswiftexample://oauth-callback/soundcloud")!, scope: "", state: state, success: {
        credential, response, parameters in

        self.saveUserData(oauthswift,credential.oauth_token)


        }, failure: { error in
            print(error.localizedDescription)
    })
}



func saveUserData(oauthswift: OAuth2Swift, _ oauthToken: String) {
    oauthswift.client.get("https://api.soundcloud.com/me?oauth_token=\(oauthToken)",
                          success: {
                            data, response in
                            //let json = JSON(data: data)
                            print("Some data")
                            let dataString = NSString(data: data, encoding: NSUTF8StringEncoding)
                            let userData = JSON(dataString!)
                            print(userData)
                            print("Some response")
                            print(response)
                            print("Extra data")

        }, failure: { error in
            print(error)
    })
}`
Originally created by @tunds on GitHub (Jul 8, 2016). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/250 So basically i'm having issues with the authentication side of things with the soundcloud api, so i'm using a webview which is programatically created and attaching this to the same view which works perfectly. The issue is once i try to authenticate using one of the options from soundcloud either Facebook, Gmail the screen is just blank and it doesn't seem to be authenticating when using the connect with Facebook or gmail the reason why i say it isn't authenticating is because nothing is being logged in the console... and the email screen seems to be stuck as you can see in the image below... There's no callback once the authentication is done and this does work since there is output in the console when i'm testing the data being returned. ![simulator screen shot 8 jul 2016 11 00 28](https://cloud.githubusercontent.com/assets/13179531/16684183/9a548bbc-44fb-11e6-9d07-70798eab6952.png) So this is the code i'm using to authenticate the user and save the users data below. ` func doOAuthSoundCloud(consumerKey: String, consumerSecret: String) { ``` let oauthswift = OAuth2Swift( consumerKey: consumerKey, consumerSecret: consumerSecret, authorizeUrl: authorizeUrl, accessTokenUrl: accessToken, responseType: "code" ) oauthswift.authorize_url_handler = AuthWebViewController() let state: String = generateStateWithLength(20) as String oauthswift.authorizeWithCallbackURL( NSURL(string: "oauthswiftexample://oauth-callback/soundcloud")!, scope: "", state: state, success: { credential, response, parameters in self.saveUserData(oauthswift,credential.oauth_token) }, failure: { error in print(error.localizedDescription) }) } func saveUserData(oauthswift: OAuth2Swift, _ oauthToken: String) { oauthswift.client.get("https://api.soundcloud.com/me?oauth_token=\(oauthToken)", success: { data, response in //let json = JSON(data: data) print("Some data") let dataString = NSString(data: data, encoding: NSUTF8StringEncoding) let userData = JSON(dataString!) print(userData) print("Some response") print(response) print("Extra data") }, failure: { error in print(error) }) }` ```
kerem 2026-03-03 16:46:04 +03:00
Author
Owner

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

Did you register oauthswiftexample url scheme in your project ?(see readme How to > Setting URL Schemes )
Did you add the code into AppDelegate to handle URL returned after login?

<!-- gh-comment-id:231360561 --> @phimage commented on GitHub (Jul 8, 2016): Did you register oauthswiftexample url scheme in your project ?(see readme How to > Setting URL Schemes ) Did you add the code into AppDelegate to handle URL returned after login?
Author
Owner

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

Yep done all of that my url scheme is: oauthswiftexample
My redirect_uri is: oauthswiftexample://oauth-callback/soundcloud/ and this is the same in my soundcloud account, also in my app delegate i have the following, this was working yesterday in my application but after today it's no dice

` func applicationHandleOpenURL(url: NSURL) {
if (url.host == "oauth-callback") {
OAuthSwift.handleOpenURL(url)
} else {
// Google provider is the only one wuth your.bundle.id url schema.
OAuthSwift.handleOpenURL(url)
}
}

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
    applicationHandleOpenURL(url)
    return true
}

@available(iOS 9.0, *)
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
    applicationHandleOpenURL(url)
    return true
}`
<!-- gh-comment-id:231365419 --> @tunds commented on GitHub (Jul 8, 2016): Yep done all of that my url scheme is: oauthswiftexample My redirect_uri is: oauthswiftexample://oauth-callback/soundcloud/ and this is the same in my soundcloud account, also in my app delegate i have the following, this was working yesterday in my application but after today it's no dice ` func applicationHandleOpenURL(url: NSURL) { if (url.host == "oauth-callback") { OAuthSwift.handleOpenURL(url) } else { // Google provider is the only one wuth your.bundle.id url schema. OAuthSwift.handleOpenURL(url) } } ``` func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { applicationHandleOpenURL(url) return true } @available(iOS 9.0, *) func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool { applicationHandleOpenURL(url) return true }` ```
Author
Owner

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

Moved the code into the actual class where the login occurs fixes this and redirection now works for Facebook and email but not google plus which i will open as a new issue

<!-- gh-comment-id:231391211 --> @tunds commented on GitHub (Jul 8, 2016): Moved the code into the actual class where the login occurs fixes this and redirection now works for Facebook and email but not google plus which i will open as a new issue
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#142
No description provided.