首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Strava身份验证中未调用ASWebAuthenticationSession completionHandler

在Strava身份验证中未调用ASWebAuthenticationSession completionHandler
EN

Stack Overflow用户
提问于 2020-01-31 16:42:31
回答 2查看 669关注 0票数 1

在Strava身份验证中单击授权按钮时,未调用ASWebAuthenticationSession completionHandler。下面给出了我的代码(使用Using ASWebAuthenticationSession to connect to Strava account fails这个链接来实现)。

代码语言:javascript
复制
import AuthenticationServices

class LinkAppsViewController: UIViewController, ASWebAuthenticationPresentationContextProviding{

func authenticate()
    {
        let string = self.createWebAuthUrl()
        guard let url = URL(string: string) else { return }

        self.authSession = ASWebAuthenticationSession(url: url, callbackURLScheme: "localhost/", completionHandler:
        {
            url, error in

        })

        self.authSession!.presentationContextProvider = self

        self.authSession?.start()
    }

    fileprivate func createWebAuthUrl() -> String
    {
        var url = String.init()

        url.append("https://www.strava.com/oauth/mobile/authorize")
        url.append("?client_id=<client id>")
        url.append("&redirect_uri=http://localhost/exchange_token")
        url.append("&response_type=code")
        url.append("&approval_prompt=force")
        url.append("&grant_type=authorization_code")
        url.append("&scope=activity:write,activity:read_all")

        return url
    }

    func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
        print(session)
        return view.window!
    }
}

我的info.plist文件看起来像这样

EN

回答 2

Stack Overflow用户

发布于 2020-08-28 14:26:18

我是通过修改我的代码得到它的..

代码语言:javascript
复制
fileprivate func createWebAuthUrlStrava() -> String
{
    var url = String.init()

    url.append("https://www.strava.com/oauth/mobile/authorize")
    url.append("?client_id=<client id>")
    url.append("&redirect_uri=abcd://localhost/exchange_token")
    url.append("&response_type=code")
    url.append("&approval_prompt=force")
    url.append("&grant_type=authorization_code")
    url.append("&scope=activity:write,activity:read_all")

    return url
}

info.plist

<client id>更改为您的客户端id,并将and更改为您的应用程序名称。

票数 1
EN

Stack Overflow用户

发布于 2021-06-05 03:36:12

我认为您将URL Scheme格式更改为abcd是正确的。但是,在初始化ASWebAuthenticationSession时传递的callbackURLScheme参数的值必须与此URL方案(abcd)相同。因此,您的代码应按如下方式更改:

代码语言:javascript
复制
self.authSession = ASWebAuthenticationSession(url: url, callbackURLScheme: "abcd", completionHandler:
{ url, error in

 })

您还可以参考Apple's official documentation了解如何使用ASWebAuthenticationSession

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60000470

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档