Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

startHTTPListener crashes on a macOS app written in Swift #107

Closed
dani-mp opened this issue Apr 10, 2017 · 8 comments
Closed

startHTTPListener crashes on a macOS app written in Swift #107

dani-mp opened this issue Apr 10, 2017 · 8 comments
Labels

Comments

@dani-mp
Copy link

dani-mp commented Apr 10, 2017

Hi. I'm having problems using AppAuth in a Swift macOS app.

I'm using Carthage as dependency manager and the integration seems to work as expected.

When I try to start the HTTP listener, I observe two different (related) issues. When I run this code:

let successURL = URL(string: "https://openid.github.io/AppAuth-iOS/redirect/")!
self.redirectHTTPHandler = OIDRedirectHTTPHandler(successURL: successURL)
let redirectURI = redirectHTTPHandler?.startHTTPListener(nil) // This line makes the app crash

I get this logged in the console: CFSocketSetAddress bind failure: 1, and then a crash in the last line of the snippet above.

I don't know why the server cannot be started in the first place, it seems to fail here, but I don't know why, and I think the crash after is due to the fact that the function startHTTPListener of OIDRedirectHTTPHandler is imported to Swift like this:

/*! @brief Starts listening on the loopback interface on a random available port, and returns a URL
            with the base address. Use the returned redirect URI to build an @c OIDAuthorizationRequest,
            and once you initiate the request, set the resulting @c OIDAuthorizationFlowSession to
            @c currentAuthorizationFlow so the response can be handled.
        @param error The error if an error occurred while starting the local HTTP server.
        @return The URL containing the address of the server with the randomly assigned available port.
        @discussion Each instance of @c OIDRedirectHTTPHandler can only listen for a single
            authorization response. Calling this more than once will result in the previous listener
            being cancelled (equivalent of @c cancelHTTPListener being called).
*/
open func startHTTPListener(_ error: NSErrorPointer) -> URL

and it should return URL? instead, right?

Thanks for your help.

@dani-mp
Copy link
Author

dani-mp commented Apr 11, 2017

I've tried adding the library to a brand new project (also macOS in Swift) and the http listener starts (and therefore the app doesn't crash after). I also made a test accessing the library from Objective-C code (which I know it's not necessary) in my app, and obviously it doesn't crash, but the http listener doesn't start either, and I get the same output in the console: CFSocketSetAddress bind failure: 1 and a nil redirect URI.

I guess there is something in my project (which isn't new) that's messing around with this, but I can't understand what. I can't find any useful info about this "bind failure" problem.

Does someone have any clue about what could be happening?

Thanks.

@WilliamDenniss
Copy link
Member

WilliamDenniss commented Apr 13, 2017

Does the Objective-C macOS sample work for you with the HTTP redirect option?

@dani-mp
Copy link
Author

dani-mp commented Apr 14, 2017

I have to check that, but probably it does, because it did in a brand new project I created to test the library.

@WilliamDenniss
Copy link
Member

Can you provide a sample to reproduce this bug?

@dani-mp
Copy link
Author

dani-mp commented Apr 30, 2017

Unfortunately I can't, the project where the problem happens belongs to a client. I've tried to reproduce the issue in a brand new project in Swift but it didn't happen. I've carefully checked the project where I experienced it, looking for places where something could affect the proper functioning of AppAuth but it's pretty straightforward code, nothing special, mostly UI stuff, and I've followed the guides closely, and checked the examples. I've even written that part in Objective C, as I commented above, in case Swift itself was the problem, but I had the same error.

@StevenEWright
Copy link
Collaborator

Would it be possible for you to provide the crash dump along with your project's build settings?

@apparentsoft
Copy link

@danielmartinprieto If your app is sandboxed, you need to set a server entitlement for your app

@dani-mp
Copy link
Author

dani-mp commented Jun 18, 2017

@apparentsoft thanks! I just wanted to confirm that this fixed my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants