如何使用 OAuth1Swift 验证具有读取、写入权限的 Trello API 用户

How to authenticate Trello API user with read, write permissions using OAuth1Swift

我正在尝试对获得 read, write Trello API 访问权限的用户进行身份验证。我正在使用 OAuth1Swift 进行身份验证,但无法添加参数来添加权限和 app name.

我们如何添加这些参数?下面是我的代码。

OAuthSwift Library

Trello API Docs

 func doOAuthTrello() {
    let oauthswift = OAuth1Swift(
        consumerKey:    "consumerKey",
        consumerSecret: "consumerSecret",
        requestTokenUrl:    "https://trello.com/1/OAuthGetRequestToken",
        authorizeUrl:       "https://trello.com/1/OAuthAuthorizeToken",
        accessTokenUrl:     "https://trello.com/1/OAuthGetAccessToken"
    )

    self.oauthswift = oauthswift
    oauthswift.authorizeURLHandler = getURLHandler()
    let _ = oauthswift.authorize(
        withCallbackURL: URL(string: "oauth-swift://oauth-callback/trello")!,
        success: { credential, response, parameters in
            self.showTokenAlert(name: serviceParameters["name"], credential: credential)
            self.testTrello(oauthswift)
        },
        failure: { error in
            print(error.localizedDescription, terminator: "")
        }
    )
}

尝试了所有方法后,这是解决方案:

lazy var paramaters:[String: String] = {
    return  [
        "consumerKey": "consumerKey",
        "consumerSecret": "consumerSecret",
        "requestTokenUrl": "https://trello.com/1/OAuthGetRequestToken?scope=read,write,account&expiration=never&name=AppName",
        "authorizeUrl": "https://trello.com/1/OAuthAuthorizeToken?scope=read,write,account&expiration=never&name=AppName",
        "accessTokenUrl": "https://trello.com/1/OAuthGetAccessToken?scope=read,write,account&expiration=never&name=AppName"
    ]
}()

通过将 ?scope=read,write,account&expiration=never&name=AppName 添加到 url 参数来实现神奇效果