I'm trying to implement authentication with StackExchange API => https://api.stackexchange.com/docs

And I'm implementing this in an application. So I decided the implicit approach.

I call the URL with my client Id => I can login and tap authorize => and I'm redirected to an URL with the access token in my hash.

The problem is that I cant configure a redirect URL. And since I'm working in an application I cant set my callback and get the access token in my app.

This is a piece of code:

    func signIn() {

// let redirectURL = "???"

    let authUrl = URL(string: "https://stackexchange.com/oauth/dialog?client_id=<MY_ID>&scope=private_info&redirect_uri=https://stackexchange.com/oauth/login_success")!
    let authSession = ASWebAuthenticationSession(url: authUrl, callbackURLScheme: ???) { (url, error) in
        if let error = error {
            print("Error : \(error.localizedDescription)")
        } else if let url = url {
            print("Success \(url)")
    authSession.presentationContextProvider = self
    authSession.prefersEphemeralWebBrowserSession = true

I cant get my access token, neither with an external lib.


I did a POC for authentication, and had set the callback URL to a Azure function. The callback URL needs to be a public API which StackExchange can call back.

My Azure function did not have any logic / did not return any value however, I was able to see the code in the URL in the browser. Maybe for your verification, grab the code from the browser URL in the callback method and make the subsequent call using postman / your code to /oauth/access_token endpoint (step 4 in the documentation).

Hope this helps!

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .