【问题标题】:Custom Headers for OAuthSwiftOAuthSwift 的自定义标头
【发布时间】:2018-04-12 23:39:31
【问题描述】:

我正在使用 OAuthSwift 对用户进行身份验证,但我已经将用户的凭据存储在 cookie 中,我需要在尝试授权之前将 cookie 设置为 OAuthSwift 实例的标头。

我知道您可以更改OAuthSwiftCredential.authorizationHeader,但是添加我自己的一组标题呢?这甚至可能吗?

oauth = OAuth2Swift(consumerKey: ""...)

// Change oauth headers here>

oauth.authorize(withCallbackURL: ""...)

【问题讨论】:

    标签: swift oauth oauth-2.0


    【解决方案1】:

    / 1. 构建授权头字符串

    let auth = OAuthSwiftClient.authorizationHeaderForMethod(method.rawValue,
        url: URLWithPath,
        parameters: parameters!,
        credential: Semantics3Router.oauthClient.credential)
    

    // 2. 请求URL

    let URLRequest = OAuthRequestBuilder.makeRequest(URLWithPath,
        method: method.rawValue,
        headers: [ "Authorization" : auth ],
        parameters: parameters!,
        dataEncoding: dataEncoding)
    

    【讨论】:

    • 这对您有帮助吗?
    • No.. authorizationHeaderForMethod 不是 OAuthSwiftClient 的函数。而 OAuthRequestBuilder 什么都不是。
    【解决方案2】:

    原来标头实际上是作为可选内容内置到 authorize 函数中的。我只是在查看源代码之前没有看到它。

    open func authorize(withCallbackURL callbackURL: URL, scope: String, 
        state: String, parameters: Parameters = [:], headers: 
        OAuthSwift.Headers? = nil, success: @escaping TokenSuccessHandler, 
        failure: FailureHandler?) -> OAuthSwiftRequestHandle?
    

    Xcode 用于显示自动填充选项的选项,我想知道为什么它不再这样做了??

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-25
      • 2018-12-18
      • 2016-04-05
      • 2011-01-04
      • 2017-02-12
      相关资源
      最近更新 更多