Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How about Auth? #24

Open
A11enFr1edman opened this issue Oct 4, 2015 · 3 comments
Open

How about Auth? #24

A11enFr1edman opened this issue Oct 4, 2015 · 3 comments
Labels

Comments

@A11enFr1edman
Copy link

Such as OAuth? or JSON Web Tokens

@kylef
Copy link
Member

kylef commented Oct 5, 2015

Hi @a11enwong,

I think the best way to deal with this right now would be to subclass Hyperdrive and modify requests inside constructRequest with your appropriate access token or authentication mechanism.

For example:

class Artsydrive: Hyperdrive {
  public override func constructRequest(uri: String, parameters: [String : AnyObject]?) -> RequestResult {
    return super.constructRequest(uri, parameters: parameters).map { request in
      request.setValue("Bearer X", forHTTPHeaderField: "Authorization")
      return request
    }
  }
}

As for performing your authorization flow to retrieve the access token. You would mostly have to do this yourself unless it is described via Hypermedia. It may make sense for us to make func request(request:NSURLRequest, completion:(RepresentorResult -> Void)) public so that you could use this for convenience.

I'd love to hear any feedback you have, I'd definitely be interested in seeing how we could improve Hyperdrive to supply a better API when it comes to authentication.

@kylef kylef added the question label Oct 5, 2015
@A11enFr1edman
Copy link
Author

Thank you very much!

@theo-beers
Copy link

It would help if we could provide our own NSURLSession with the constructor of the Hyperdrive instance.
We could then set custom headers by using the configuration, or provide authentication logic by using a delegate on the session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants