Edmund Edmund - 1 year ago 147
iOS Question

Square API + OAuth2: How do I set my redirect URL to my iOS app?

I am trying to implement OAuth2 in my iOS app through Square but it's saying there is an error with my redirect_uri when I sign in successfully through the browser that pops up.

enter image description here

I'm using the OAuthSwift pod. This is what I have so far to set up the URL scheme so that the redirect should open my iOS app:

Square dashboard config:

enter image description here


class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
print("hollaaaaaaaaaaaaaaaaa") // i never see this printed
OAuthSwift.handle(url: url)
return true


enter image description here

Controller that opens the browser:

class OAuthViewController: UIViewController {

@IBAction func signInButtonTapped(_ sender: AnyObject) {

let oauthswift = OAuth2Swift(
consumerKey: "my token",
consumerSecret: "my secret",
authorizeUrl: "https://connect.squareup.com/oauth2/authorize?client_id=my_id",
responseType: "token"
withCallbackURL: URL(string: "com.edmund.ios/oauth-callback")!, // doesn't seem to do anything honestly... I think the Square dashboard setting has precedence over this.
state: "",
success: { (credential, response, parameters) -> Void in
failure: { error in


Answer Source

When you guide a user through the oauth flow for your app, you must specify a redirect_uri parameter that matches that value you have specified in the Square developer portal. Note that this redirect_uri must start with http or https and correspond to a webpage on your server.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download