Поскольку Linkedin iOS Поддержка SDK закрыта, я пытаюсь интегрировать веб-авторизацию. Я могу получить вид входа в систему и следующую страницу «Разрешить страницу разрешения». Пример изображения с LinkedIn
Но кнопка разрешения отключена. В идеале он должен перенаправить меня на правильный redirect_uri.
Код, который я использую для загрузки страницы входа на сайте LinkIn в веб-просмотр
let authorizationEndPoint = "https://www.linkedin.com/uas/oauth2/authorization"
let linkedInKey = "8xch02uxrojt6a"
// Specify the response type which should always be "code".
let responseType = "code"
// Set the redirect URL. Adding the percent escape characthers is necessary.
if let redirectURL =
"redirectionURL".addingPercentEncoding(withAllowedCharacters:(.urlHostAllowed))
{
let state = "ABC\(Int(NSDate().timeIntervalSince1970))"
// Set preferred scope.
let scope = "r_emailaddress"
// Create the authorization URL string.
var authorizationURL = "\(authorizationEndPoint)?"
authorizationURL += "response_type=\(responseType)&"
authorizationURL += "client_id=\(linkedInKey)&"
authorizationURL += "redirect_uri=\(redirectURL)&"
authorizationURL += "state=\(state)&"
authorizationURL += "scope=\(scope)"
print(authorizationURL)
// Create a URL request and load it in the web view.
let url = URL(string: authorizationURL)
webView.navigationDelegate = self
webView.load(URLRequest(url: url!))
}
Интернет Навигационный делегат
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
let url = webView.url!
print("Started to load", url)
if url.host == "www.ABC.com/auth/linkedin" {
if url.absoluteString.contains("code") {
// Extract the authorization code.
let urlParts = url.absoluteString.split(separator:"?")
let code = urlParts[1].split(separator:"=")[1]
requestForAccessToken(authorizationCode: String(code))
}
}
//return true
}