[GH-ISSUE #258] Instagram login issue #150

Closed
opened 2026-03-03 16:46:07 +03:00 by kerem · 26 comments
Owner

Originally created by @floriangbh on GitHub (Aug 5, 2016).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/258

Hi,

I'm trying to make Instagram login. There is my code :
• Instagram Manager

import UIKit
import OAuthSwift

class GFInstagramManager: NSObject {
    static let shared = GFInstagramManager()

    var oauthswift: OAuthSwift?

    func login() {
        let oauthswift = OAuth2Swift(
            consumerKey:    "****...",
            consumerSecret: "****...",
            authorizeUrl:   "https://api.instagram.com/oauth/authorize",
            responseType:   "token"
        )
        oauthswift.authorizeWithCallbackURL(
            NSURL(string: "http://oauthswift.herokuapp.com/callback/instagram")!,
            scope: "likes+comments", state:"INSTAGRAM",
            success: { credential, response, parameters in
                print(response.debugDescription)
                print(credential.oauth_token)
            },
            failure: { error in
                print(error.localizedDescription)
            }
        )
    }
    func testInstagram(oauthswift: OAuth2Swift) {
        let url :String = "https://api.instagram.com/v1/users/1574083/?access_token=\(oauthswift.client.credential.oauth_token)"
        let parameters :Dictionary = Dictionary<String, AnyObject>()
        oauthswift.client.get(url, parameters: parameters,
                              success: {
                                data, response in
                                let jsonDict: AnyObject! = try? NSJSONSerialization.JSONObjectWithData(data, options: [])
                                print(jsonDict)

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

• ApplicationDelegate

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

    @available(iOS 9.0, *)
    func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool
    {
        applicationHandleOpenURL(url)
        FBSDKApplicationDelegate.sharedInstance().application(app, openURL: url, sourceApplication: options["UIApplicationOpenURLOptionsSourceApplicationKey"] as! String, annotation: options["UIApplicationOpenURLOptionsAnnotationKey"])
        return true
    }

// MARK: handle callback url
extension AppDelegate {

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

• URL Types

capture d ecran 2016-08-05 a 16 51 20

Login are done, but when the login view disappear my callback pass in error with "No access_token, no code and no error provided by server"

My Instagram URL/ call back url is "http://oauthswift.herokuapp.com/callback/instagram"... I don't know if it's the good way..
(my consumer et secret key work on our Android app)

Anyone have idea ?

  • OS targeted (with version): 8.0
  • OAuth provider: Instagram
  • OAuthSwift version: Master 0.5.0'
Originally created by @floriangbh on GitHub (Aug 5, 2016). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/258 Hi, I'm trying to make Instagram login. There is my code : • Instagram Manager ``` import UIKit import OAuthSwift class GFInstagramManager: NSObject { static let shared = GFInstagramManager() var oauthswift: OAuthSwift? func login() { let oauthswift = OAuth2Swift( consumerKey: "****...", consumerSecret: "****...", authorizeUrl: "https://api.instagram.com/oauth/authorize", responseType: "token" ) oauthswift.authorizeWithCallbackURL( NSURL(string: "http://oauthswift.herokuapp.com/callback/instagram")!, scope: "likes+comments", state:"INSTAGRAM", success: { credential, response, parameters in print(response.debugDescription) print(credential.oauth_token) }, failure: { error in print(error.localizedDescription) } ) } func testInstagram(oauthswift: OAuth2Swift) { let url :String = "https://api.instagram.com/v1/users/1574083/?access_token=\(oauthswift.client.credential.oauth_token)" let parameters :Dictionary = Dictionary<String, AnyObject>() oauthswift.client.get(url, parameters: parameters, success: { data, response in let jsonDict: AnyObject! = try? NSJSONSerialization.JSONObjectWithData(data, options: []) print(jsonDict) }, failure: { error in print(error) }) } } ``` • ApplicationDelegate ``` func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { applicationHandleOpenURL(url) return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) } @available(iOS 9.0, *) func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool { applicationHandleOpenURL(url) FBSDKApplicationDelegate.sharedInstance().application(app, openURL: url, sourceApplication: options["UIApplicationOpenURLOptionsSourceApplicationKey"] as! String, annotation: options["UIApplicationOpenURLOptionsAnnotationKey"]) return true } // MARK: handle callback url extension AppDelegate { func applicationHandleOpenURL(url: NSURL) { if (url.host == "oauth-callback") { print("PASSS1") OAuthSwift.handleOpenURL(url) print("PASSS2") } else { // Google provider is the only one wuth your.bundle.id url schema. OAuthSwift.handleOpenURL(url) } } } ``` • URL Types <img width="886" alt="capture d ecran 2016-08-05 a 16 51 20" src="https://cloud.githubusercontent.com/assets/14054997/17440432/e7b9916c-5b2c-11e6-92bd-319894286248.png"> Login are done, but when the login view disappear my callback pass in error with "No access_token, no code and no error provided by server" My Instagram URL/ call back url is "http://oauthswift.herokuapp.com/callback/instagram"... I don't know if it's the good way.. (my consumer et secret key work on our Android app) Anyone have idea ? - **OS targeted (with version):** 8.0 - **OAuth provider:** Instagram - **OAuthSwift version:** Master 0.5.0'
kerem 2026-03-03 16:46:07 +03:00
Author
Owner

@phimage commented on GitHub (Aug 6, 2016):

In your code I see :
let oauthswift =
and not
self.oauthswift =
so the object could be released

Your version is 0.5.0 or 0.5.1 or 0.5.2?

I don't known about instagram but some provider need you to declare the callbackurl for your application (associated with your secret and consumer key)

state:"INSTAGRAM" : maybe not authorized (in demo app we use random string)

Maybe you can find information in previous issues
https://github.com/OAuthSwift/OAuthSwift/search?q=instagram&type=Issues&utf8=%E2%9C%93

using herokuapp.com is only to test with url scheme oauth-swift (in production use your own app scheme)

<!-- gh-comment-id:238010806 --> @phimage commented on GitHub (Aug 6, 2016): In your code I see : let oauthswift = and not self.oauthswift = so the object could be released Your version is 0.5.0 or 0.5.1 or 0.5.2? I don't known about instagram but some provider need you to declare the callbackurl for your application (associated with your secret and consumer key) state:"INSTAGRAM" : maybe not authorized (in demo app we use random string) Maybe you can find information in previous issues https://github.com/OAuthSwift/OAuthSwift/search?q=instagram&type=Issues&utf8=%E2%9C%93 using herokuapp.com is only to test with url scheme oauth-swift (in production use your own app scheme)
Author
Owner

@floriangbh commented on GitHub (Aug 6, 2016):

Thank your for your response !

This is the cocoapod 0.5.0 version.

Firstly I'm not able to use the demo app with instagram, I do not undestrand the redirection URI which I need to put in the project and in Instagram dev website...
Can you give me an example with step for user Instagram connect with the demo app ? (except for API key)

I can't put oauth-swift://oauth-callback/instagram in Instagram website like in this post for exemple : https://github.com/OAuthSwift/OAuthSwift/issues/53

With this code (in demo app) :

        let state: String = generateStateWithLength(20) as String
        self.oauthswift = oauthswift
        oauthswift.authorize_url_handler = get_url_handler()
        oauthswift.authorizeWithCallbackURL( NSURL(string: "http://oauthswift.herokuapp.com/callback/instagram")!, scope: "basic", state:state, success: {
            credential, response, parameters in
            print("pass")
            self.showTokenAlert(serviceParameters["name"], credential: credential)
            self.testInstagram(oauthswift)
            }, failure: { error in
                print(error.localizedDescription)
        })

It pass in success callback, with "No access_token, no code and no error provided by server"... :'(

<!-- gh-comment-id:238013657 --> @floriangbh commented on GitHub (Aug 6, 2016): Thank your for your response ! This is the cocoapod 0.5.0 version. Firstly I'm not able to use the demo app with instagram, I do not undestrand the redirection URI which I need to put in the project and in Instagram dev website... Can you give me an example with step for user Instagram connect with the demo app ? (except for API key) I can't put oauth-swift://oauth-callback/instagram in Instagram website like in this post for exemple : https://github.com/OAuthSwift/OAuthSwift/issues/53 With this code (in demo app) : ``` let state: String = generateStateWithLength(20) as String self.oauthswift = oauthswift oauthswift.authorize_url_handler = get_url_handler() oauthswift.authorizeWithCallbackURL( NSURL(string: "http://oauthswift.herokuapp.com/callback/instagram")!, scope: "basic", state:state, success: { credential, response, parameters in print("pass") self.showTokenAlert(serviceParameters["name"], credential: credential) self.testInstagram(oauthswift) }, failure: { error in print(error.localizedDescription) }) ``` It pass in success callback, with "No access_token, no code and no error provided by server"... :'(
Author
Owner

@ZsoltMaslanyi commented on GitHub (Aug 6, 2016):

"I can't put oauth-swift://oauth-callback/instagram in Instagram website"

I'm having the exact same problem as Instagram tries to force an absolute URI that starts with http or https. Just sent them a message, will post here if I get a meaningful response.

<!-- gh-comment-id:238019389 --> @ZsoltMaslanyi commented on GitHub (Aug 6, 2016): "I can't put oauth-swift://oauth-callback/instagram in Instagram website" I'm having the exact same problem as Instagram tries to force an absolute URI that starts with http or https. Just sent them a message, will post here if I get a meaningful response.
Author
Owner

@floriangbh commented on GitHub (Aug 6, 2016):

Nice, waiting for your response, thank's :-)

But I think there are other way with 0AuthSwift... I just don't don't understand how does it work...

<!-- gh-comment-id:238019433 --> @floriangbh commented on GitHub (Aug 6, 2016): Nice, waiting for your response, thank's :-) But I think there are other way with 0AuthSwift... I just don't don't understand how does it work...
Author
Owner
<!-- gh-comment-id:238052359 --> @phimage commented on GitHub (Aug 6, 2016): https://github.com/OAuthSwift/OAuthSwift/wiki/API-with-only-HTTP-scheme-into-callback-URL
Author
Owner

@ZsoltMaslanyi commented on GitHub (Aug 7, 2016):

Thanks @phimage !

<!-- gh-comment-id:238080925 --> @ZsoltMaslanyi commented on GitHub (Aug 7, 2016): Thanks @phimage !
Author
Owner

@ZsoltMaslanyi commented on GitHub (Aug 9, 2016):

Hey guys,

Thanks to @phimage 's link on the HTTP only callback URL I was able to move forward, but got stuck with a weird phenomenon that's the same as @terflogag 's original problem.

When trying to do implicit auth for Instagram, after a successful authentication (logging in with a Sandbox user) Instagram's response does not include an access token and there's no error messages either.

I wrote my own server app so I can have a valid callback URL that I can monitor, and weirdly enough the "state" parameter gets passed along from Instagram, but no access token and no error messages.

I've tried using various authorize_url_handlers, I've tried the original demo app, I've downloaded the sample server app that does the redirect and deployed it again thinking the problem was with my own server solution, but the result is the same.

Any help would be greatly appreciated!

<!-- gh-comment-id:238680684 --> @ZsoltMaslanyi commented on GitHub (Aug 9, 2016): Hey guys, Thanks to @phimage 's link on the HTTP only callback URL I was able to move forward, but got stuck with a weird phenomenon that's the same as @terflogag 's original problem. When trying to do implicit auth for Instagram, after a successful authentication (logging in with a Sandbox user) Instagram's response does _not_ include an access token and there's no error messages either. I wrote my own server app so I can have a valid callback URL that I can monitor, and weirdly enough the "state" parameter gets passed along from Instagram, but no access token and no error messages. I've tried using various authorize_url_handlers, I've tried the original demo app, I've downloaded the sample server app that does the redirect and deployed it again thinking the problem was with my own server solution, but the result is the same. Any help would be greatly appreciated!
Author
Owner

@ejpusa-zz commented on GitHub (Aug 10, 2016):

If you start from scratch with the IG demo on the site, it does work.
OAuth2 is super complex. Plus your mobile is a moving target.

Think adding OAuth2 to an existing App is a bit tough. But starting first
with a working OAuth2 app, totally bare-bones, and than building out from
there has worked for me.

Bare-Bare-Bare bones. :-)

On Tue, Aug 9, 2016 at 4:29 PM, Zsolt Maslanyi notifications@github.com
wrote:

Hey guys,

Thanks to @phimage https://github.com/phimage 's link on the HTTP only
callback URL I was able to move forward, but got stuck with a weird
phenomenon that's the same as @terflogag https://github.com/terflogag
's original problem.

When trying to do implicit auth for Instagram, after a successful
authentication Instagram's response does not include an access token
and there's no error messages either.

I wrote my own server app so I can have a valid callback URL that I can
monitor, and weirdly enough the "state" parameter gets passed along from
Instagram, but no access token and no error messages.

I've tried using various authorize_url_handlers, I've tried the original
demo app, I've downloaded the sample server app that does the redirect and
deployed it again thinking the problem was with my own server solution, but
the result is the same.

Any help would be greatly appreciated!


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/OAuthSwift/OAuthSwift/issues/258#issuecomment-238680684,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABOHS8o4G4gGOWa389z-pSNq63FOlUARks5qeOMUgaJpZM4Jdwon
.


@ejpusa http://twitter.com/ejpusa

<!-- gh-comment-id:238745878 --> @ejpusa-zz commented on GitHub (Aug 10, 2016): If you start from scratch with the IG demo on the site, it does work. OAuth2 is super complex. Plus your mobile is a moving target. Think adding OAuth2 to an existing App is a bit tough. But starting first with a working OAuth2 app, totally bare-bones, and than building out from there has worked for me. Bare-Bare-Bare bones. :-) On Tue, Aug 9, 2016 at 4:29 PM, Zsolt Maslanyi notifications@github.com wrote: > Hey guys, > > Thanks to @phimage https://github.com/phimage 's link on the HTTP only > callback URL I was able to move forward, but got stuck with a weird > phenomenon that's the same as @terflogag https://github.com/terflogag > 's original problem. > > When trying to do implicit auth for Instagram, after a successful > authentication Instagram's response does _not_ include an access token > and there's no error messages either. > > I wrote my own server app so I can have a valid callback URL that I can > monitor, and weirdly enough the "state" parameter gets passed along from > Instagram, but no access token and no error messages. > > I've tried using various authorize_url_handlers, I've tried the original > demo app, I've downloaded the sample server app that does the redirect and > deployed it again thinking the problem was with my own server solution, but > the result is the same. > > Any help would be greatly appreciated! > > — > You are receiving this because you are subscribed to this thread. > Reply to this email directly, view it on GitHub > https://github.com/OAuthSwift/OAuthSwift/issues/258#issuecomment-238680684, > or mute the thread > https://github.com/notifications/unsubscribe-auth/ABOHS8o4G4gGOWa389z-pSNq63FOlUARks5qeOMUgaJpZM4Jdwon > . ## --- @ejpusa http://twitter.com/ejpusa
Author
Owner

@floriangbh commented on GitHub (Aug 10, 2016):

Even with the demo I stay stuck with "No access_token, no code and no error provided by server"...

I will try again tonight, and post here if it work.

<!-- gh-comment-id:238780770 --> @floriangbh commented on GitHub (Aug 10, 2016): Even with the demo I stay stuck with "No access_token, no code and no error provided by server"... I will try again tonight, and post here if it work.
Author
Owner

@ZsoltMaslanyi commented on GitHub (Aug 10, 2016):

@ejpusa: Thanks for chiming in!

As I mentioned, even the demo app didn't work for me.

I've registered a new Instagram client on their dev site, which only accepts callback URLs starting with http. Thanks to @phimage 's wiki on that issue ( https://github.com/OAuthSwift/OAuthSwift/wiki/API-with-only-HTTP-scheme-into-callback-URL ) I've deployed the demo server app that's on this wiki, registered it as a callback URL and had the same result: I successfully log in with a sandbox user, Instagram calls the registered callback URL but there's no access token and no error messages. Strangely enough it does pass the "state" parameter it was called with.

<!-- gh-comment-id:238890870 --> @ZsoltMaslanyi commented on GitHub (Aug 10, 2016): @ejpusa: Thanks for chiming in! As I mentioned, even the demo app didn't work for me. I've registered a new Instagram client on their dev site, which only accepts callback URLs starting with http. Thanks to @phimage 's wiki on that issue ( https://github.com/OAuthSwift/OAuthSwift/wiki/API-with-only-HTTP-scheme-into-callback-URL ) I've deployed the demo server app that's on this wiki, registered it as a callback URL and had the same result: I successfully log in with a sandbox user, Instagram calls the registered callback URL but there's no access token and no error messages. Strangely enough it does pass the "state" parameter it was called with.
Author
Owner

@floriangbh commented on GitHub (Aug 11, 2016):

I tred again, same problem...

with :

let state: String = generateStateWithLength(20) as String
        self.oauthswift = oauthswift
        oauthswift.authorize_url_handler = get_url_handler()
        oauthswift.authorizeWithCallbackURL( NSURL(string: "http://oauthswift.herokuapp.com/callback/instagram")!, scope: "basic", state:state, success: {
            credential, response, parameters in
            self.showTokenAlert(serviceParameters["name"], credential: credential)
            self.testInstagram(oauthswift)
            }, failure: { error in
                print(error.localizedDescription)
        })

in the demo app (juste change URL and scope), and same url in Instagram dev center.

With this I successfully log in but have "No access_token, no code and no error provided by server"

<!-- gh-comment-id:239095874 --> @floriangbh commented on GitHub (Aug 11, 2016): I tred again, same problem... with : ``` let state: String = generateStateWithLength(20) as String self.oauthswift = oauthswift oauthswift.authorize_url_handler = get_url_handler() oauthswift.authorizeWithCallbackURL( NSURL(string: "http://oauthswift.herokuapp.com/callback/instagram")!, scope: "basic", state:state, success: { credential, response, parameters in self.showTokenAlert(serviceParameters["name"], credential: credential) self.testInstagram(oauthswift) }, failure: { error in print(error.localizedDescription) }) ``` in the demo app (juste change URL and scope), and same url in Instagram dev center. With this I successfully log in but have "No access_token, no code and no error provided by server"
Author
Owner

@ZsoltMaslanyi commented on GitHub (Aug 11, 2016):

@phimage @terflogag : Hey guys, this might be a real issue. Anyone we could notify to take a look if they have the time? (I'll try to look at the source myself but I'm not familiar with it)

<!-- gh-comment-id:239273649 --> @ZsoltMaslanyi commented on GitHub (Aug 11, 2016): @phimage @terflogag : Hey guys, this might be a real issue. Anyone we could notify to take a look if they have the time? (I'll try to look at the source myself but I'm not familiar with it)
Author
Owner

@phimage commented on GitHub (Aug 11, 2016):

sorry I have no access to a mac os environment for the moment (holiday)
The error "No access_token, no code and no error provided by server" occurs in :
authorizeWithCallbackURL function l73 in OAuth2Swift.swift
there is a local variable responseParameters filled with URL query or/and fragment

if you can put a breakpoint on var responseParameters = [String: String](), I am interested in url value
then responseParameters value after query + fragment addition (6 lines after)

<!-- gh-comment-id:239283090 --> @phimage commented on GitHub (Aug 11, 2016): sorry I have no access to a mac os environment for the moment (holiday) The error "No access_token, no code and no error provided by server" occurs in : `authorizeWithCallbackURL` function l73 in OAuth2Swift.swift there is a local variable `responseParameters` filled with URL query or/and fragment if you can put a breakpoint on `var responseParameters = [String: String]()`, I am interested in `url` value then `responseParameters` value after query + fragment addition (6 lines after)
Author
Owner

@ZsoltMaslanyi commented on GitHub (Aug 11, 2016):

@phimage Thanks for the hint!

I'll give it a look tomorrow and post my findings.

In the meantime, enjoy your holiday! :)

<!-- gh-comment-id:239283736 --> @ZsoltMaslanyi commented on GitHub (Aug 11, 2016): @phimage Thanks for the hint! I'll give it a look tomorrow and post my findings. In the meantime, enjoy your holiday! :)
Author
Owner

@parthjdabhi commented on GitHub (Aug 12, 2016):

@phimage i have also applied same, and get state parameter only in callback url

<!-- gh-comment-id:239376526 --> @parthjdabhi commented on GitHub (Aug 12, 2016): @phimage i have also applied same, and get state parameter only in callback url
Author
Owner

@phimage commented on GitHub (Aug 12, 2016):

Instead of redirecting to callback URL with error filled, maybe instagram just return some json. (not correct oauth flow... but maybe only for configuration error...)
Trying with web browser to authentificate (because I have no access to mac computer) using url
https://www.instagram.com/oauth/authorize/?client_id=MyID&redirect_uri=http://oauthswift.herokuapp.com/callback/instagram&response_type=token

{
code: 403,
error_type: "OAuthForbiddenException",
error_message: "Implicit authentication is disabled"
}

So I edit my application client in instagram and uncheck "Disable implicit OAuth" to make response_type=token working (see https://www.instagram.com/developer/authentication/ Client-Side (Implicit) Authentication )

I change the callback url to http://localhost also to test and I receive
http://localhost/#access_token=XXXX
so the data was in url fragment

Also, be sure to uncheck the "Disable implicit OAuth" box or else this method will not work.

<!-- gh-comment-id:239381075 --> @phimage commented on GitHub (Aug 12, 2016): Instead of redirecting to callback URL with error filled, maybe instagram just return some json. (not correct oauth flow... but maybe only for configuration error...) Trying with web browser to authentificate (because I have no access to mac computer) using url https://www.instagram.com/oauth/authorize/?client_id=MyID&redirect_uri=http://oauthswift.herokuapp.com/callback/instagram&response_type=token ``` swift { code: 403, error_type: "OAuthForbiddenException", error_message: "Implicit authentication is disabled" } ``` So I edit my application client in instagram and uncheck "Disable implicit OAuth" to make response_type=token working (see https://www.instagram.com/developer/authentication/ Client-Side (Implicit) Authentication ) I change the callback url to http://localhost also to test and I receive http://localhost/#access_token=XXXX so the data was in url fragment **Also, be sure to uncheck the "Disable implicit OAuth" box or else this method will not work.**
Author
Owner

@ZsoltMaslanyi commented on GitHub (Aug 12, 2016):

@phimage : Thanks for looking into it!

I think I've found the problem: Both me and @terflogag were using a server-side redirect to get the token, but the access token is getting sent as an URL fragment. (it's after a hashmark)

An URL fragment is meant to be used by the browsers only, to point to an anchor within a document. As it doesn’t affect which resource is returned from the server the anchor part never makes it into the URL on the server side.

I'm not sure how I'm going to work around this just yet, but huge thanks to @phimage for shedding light to the problem! I owe you a beer :)

UPDATE:

I just hooked up everything to an internal webview and it worked like a charm. From my end the case is closed. Thanks again for the great support!

It might worth adding a one-liner to the http only scheme wiki about Instagram or URL fragments so others won't have to go through this again. Also, maybe adding a link to that wiki to the main documentation would also help as more and more providers use http only schemes.

@terflogag @parthjdabhi : If you guys get stuck doing the internal webview thing I'd be happy to send over a step-by-step guide!

<!-- gh-comment-id:239529341 --> @ZsoltMaslanyi commented on GitHub (Aug 12, 2016): @phimage : Thanks for looking into it! I think I've found the problem: Both me and @terflogag were using a server-side redirect to get the token, but the access token is getting sent as an URL fragment. (it's after a hashmark) An URL fragment is meant to be used by the browsers only, to point to an anchor within a document. As it doesn’t affect which resource is returned from the server the anchor part never makes it into the URL on the server side. I'm not sure how I'm going to work around this just yet, but huge thanks to @phimage for shedding light to the problem! I owe you a beer :) UPDATE: I just hooked up everything to an internal webview and it worked like a charm. From my end the case is closed. Thanks again for the great support! It might worth adding a one-liner to the http only scheme wiki about Instagram or URL fragments so others won't have to go through this again. Also, maybe adding a link to that wiki to the main documentation would also help as more and more providers use http only schemes. @terflogag @parthjdabhi : If you guys get stuck doing the internal webview thing I'd be happy to send over a step-by-step guide!
Author
Owner

@phimage commented on GitHub (Aug 13, 2016):

https://github.com/OAuthSwift/OAuthSwift/wiki/Instagram

<!-- gh-comment-id:239618089 --> @phimage commented on GitHub (Aug 13, 2016): https://github.com/OAuthSwift/OAuthSwift/wiki/Instagram
Author
Owner

@ZsoltMaslanyi commented on GitHub (Aug 13, 2016):

@phimage: Awesome!

Please add one more line, something like: "Use the internal web browser technique to access the token. (See the demo app on how to do it). The server redirect technique won't work as the token is in an url fragment which doesn't make it into the URL when calling a server app."

<!-- gh-comment-id:239619211 --> @ZsoltMaslanyi commented on GitHub (Aug 13, 2016): @phimage: Awesome! Please add one more line, something like: "Use the internal web browser technique to access the token. (See the demo app on how to do it). The server redirect technique won't work as the token is in an url fragment which doesn't make it into the URL when calling a server app."
Author
Owner

@phimage commented on GitHub (Aug 19, 2016):

e35c7a2 point out where to handle callback url in iOS demo if no application scheme configured and want to handle in webview directly (only OSX use that method)

<!-- gh-comment-id:240927884 --> @phimage commented on GitHub (Aug 19, 2016): e35c7a2 point out where to handle callback url in iOS demo if no application scheme configured and want to handle in webview directly (only OSX use that method)
Author
Owner

@carobeta commented on GitHub (Oct 26, 2016):

It's possible make Instagram login from the app and not from the browser?

Thanks!

<!-- gh-comment-id:256367579 --> @carobeta commented on GitHub (Oct 26, 2016): It's possible make Instagram login from the app and not from the browser? Thanks!
Author
Owner

@phimage commented on GitHub (Oct 26, 2016):

@carobeta please read the readme.md, authorize url handler

<!-- gh-comment-id:256376186 --> @phimage commented on GitHub (Oct 26, 2016): @carobeta please read the readme.md, authorize url handler
Author
Owner

@saityoukou commented on GitHub (Nov 22, 2016):

i find below solution work fine.

1.set dummyCallbackUrl to swift.
static let instagramDummyCallbackUrl = "http://xxxx.jp/redirect-instagram.html"

2.also set instagram develop -> security-> Valid redirect URIs:
"http://xxxx.jp/redirect-instagram.html"

3.use dummyCallbackUrl to call OauthSwift.authrize (i use old version:0.4.8)
oauthswift.authorizeWithCallbackURL(NSURL(string: OAuthApi.instagramDummyCallbackUrl)!, scope: "basic", state: "INSTAGRAM", success: {

4.use @phimage -> "Handle a specific URL into delegate" wiki.

https://github.com/OAuthSwift/OAuthSwift/wiki/API-with-only-HTTP-scheme-into-callback-URL

below is my code.

func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
    let urlString = request.URL!.absoluteString
    if urlString.hasPrefix("\(OAuthApi.instagramDummyCallbackUrl)") {
        OAuthSwift.handleOpenURL(request.URL!)
        self.dismissWebViewController()
    }
    return true
}

that work!!

<!-- gh-comment-id:262156816 --> @saityoukou commented on GitHub (Nov 22, 2016): i find below solution work fine. 1.set dummyCallbackUrl to swift. static let instagramDummyCallbackUrl = "http://xxxx.jp/redirect-instagram.html" 2.also set instagram develop -> security-> Valid redirect URIs: "http://xxxx.jp/redirect-instagram.html" 3.use dummyCallbackUrl to call OauthSwift.authrize (i use old version:0.4.8) oauthswift.authorizeWithCallbackURL(NSURL(string: OAuthApi.instagramDummyCallbackUrl)!, scope: "basic", state: "INSTAGRAM", success: { 4.use @phimage -> "Handle a specific URL into delegate" wiki. https://github.com/OAuthSwift/OAuthSwift/wiki/API-with-only-HTTP-scheme-into-callback-URL below is my code. func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool { let urlString = request.URL!.absoluteString if urlString.hasPrefix("\(OAuthApi.instagramDummyCallbackUrl)") { OAuthSwift.handleOpenURL(request.URL!) self.dismissWebViewController() } return true } that work!!
Author
Owner

@nitrag commented on GitHub (Jul 27, 2017):

Who has working code with SafariURLHandler that is able to handle the URL Fragment?

<!-- gh-comment-id:318249624 --> @nitrag commented on GitHub (Jul 27, 2017): Who has working code with `SafariURLHandler` that is able to handle the URL Fragment?
Author
Owner

@phimage commented on GitHub (Jul 27, 2017):

@nitrag the wiki page about instagram say to use a webview delegate in an internal web browser
so I think we cannot do anything with SafariURLHandler except If we find a way to be notified for each url loaded in SFSafariViewController. I don't see in the delegate any callback for that, only for initial url

<!-- gh-comment-id:318285239 --> @phimage commented on GitHub (Jul 27, 2017): @nitrag the wiki page about instagram say to use a webview delegate in an internal web browser so I think we cannot do anything with SafariURLHandler except If we find a way to be notified for each url loaded in SFSafariViewController. I don't see in the delegate any callback for that, only for initial url
Author
Owner

@vyasdarshan commented on GitHub (Nov 10, 2017):

Do anyone get any success by using SFSafariViewController for Instagram login?

<!-- gh-comment-id:343467241 --> @vyasdarshan commented on GitHub (Nov 10, 2017): Do anyone get any success by using SFSafariViewController for Instagram login?
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#150
No description provided.