Code Monkey home page Code Monkey logo

Comments (7)

p2 avatar p2 commented on July 21, 2024

No plans at this time. You can use oauth.request(forURL: NSURL) to get a NSURLRequest that is already signed.

from oauth2.

kimdv avatar kimdv commented on July 21, 2024

But i was thinking of automating this process

from oauth2.

p2 avatar p2 commented on July 21, 2024

Sure, I'll keep this open. But I'm not using Alamofire, so I'm unlikely to build this link any time soon.

from oauth2.

p2 avatar p2 commented on July 21, 2024

Maybe that sounds too negative, let me try again: Alamofire may be used for requests in the future, but I don't know how soon this will be.

from oauth2.

kimdv avatar kimdv commented on July 21, 2024

👍

from oauth2.

p2 avatar p2 commented on July 21, 2024

So one way to use OAuth2 with Alamofire is by setting the header manually:

let headers = [
    "Authorization": "Bearer \(oauth2.accessToken)",
]

Alamofire.request(.GET, "http://httpbin.org/get", headers: headers)

Alternatively, here's an extension so you can use your OAuth2 instance in place of Alamofire:

import Alamofire

extension OAuth2 {
    public func request(
        method: Alamofire.Method,
        _ URLString: URLStringConvertible,
        parameters: [String: AnyObject]? = nil,
        encoding: Alamofire.ParameterEncoding = .URL,
        headers: [String: String]? = nil)
        -> Alamofire.Request
    {
        var hdrs = headers
        hdrs["Authorization"] = "Bearer \(accessToken)"
        return Alamofire.request(
            method,
            URLString,
            parameters: parameters,
            encoding: encoding,
            headers: hdrs)
    }
}

oauth2.request(.GET, "http://httpbin.org/get")

I have not tested this myself yet, feedback and suggestions welcome!

from oauth2.

p2 avatar p2 commented on July 21, 2024

Added to the readme on develop branch.

from oauth2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.