Reputation: 532
I am developing one iPhone app in which I need to implement login with hubspot. To implement this, I used oauth2 library in swift. In this I am using below code to do authorization. When I run the app, its navigating me to safari and asking to enter id and passwrod of Hubspot. When I enter it, its just keep me inside the website and showing 3 dots loading.
{
let oauthswift = OAuth2Swift(
consumerKey: "****",
consumerSecret: "****",
authorizeUrl: "https://app.hubspot.com/oauth/authorize",
accessTokenUrl: "https://api.hubapi.com/oauth/v1/token",
responseType : "code"
)
oauthswift.authorize(withCallbackURL: URL(string: "myapp://"), scope: "contacts", state:"code", success: { (credentials, response, parameters) in
print(response as Any)
}, failure: { (error) in
print(error)
})
}
Upvotes: 0
Views: 1271
Reputation: 1731
I think you forgot about adding custom URL Scheme to your app. You have to go to your target settings, open tab Info and add new URL scheme under "URL Types". Remember to set "URL Schemes" to the same value as your callback URL scheme (it will be myapp
in your case, but I will recommend you to change to something more specific to your app, like your bundle id). Also, you have to implement application(_:open:options:)
method (Docs) in your AppDelegate:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if (url.host == "myapp") {
OAuthSwift.handle(url: url)
}
return true
}
All these steps are written in this library read me: https://github.com/OAuthSwift/OAuthSwift
This is how URL Types
section looks like (and remember that you have to put your callback URL scheme - myapp
)
Upvotes: 1