[GH-ISSUE #330] Use custom HTTP header for Bearer token? #203

Closed
opened 2026-03-03 16:46:38 +03:00 by kerem · 4 comments
Owner

Originally created by @underbjerg on GitHub (Jan 11, 2017).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/330

Description:

We would like to be able to configure which header to use for passing the token in requests. Currently the OAuthSwiftClient is hardcoded to use the "Authorization" header. We would like to be able to use "X-Authorization" instead.

Other than modifying the framework code, can you suggest a solution? Or consider it as a feature request?

OAuth Provider (Twitter, Github, ..):

Custom backend.

OAuth Version:

  • Version 1
  • Version 2

OS (Please fill the version) :

  • iOS :
  • OSX :
  • TVOS :
  • WatchOS :

Installation method:

  • Carthage
  • CocoaPods
  • Manually

Library version:

  • head
  • v1.0.0
  • v0.6
  • other: (Please fill in the version you are using.)

Xcode version:

  • 8.0 (Swift 3.0)

  • 8.0 (Swift 2.3)

  • 7.3.1

  • other: (Please fill in the version you are using.)

  • objective c

Originally created by @underbjerg on GitHub (Jan 11, 2017). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/330 ### Description: We would like to be able to configure which header to use for passing the token in requests. Currently the OAuthSwiftClient is hardcoded to use the "Authorization" header. We would like to be able to use "X-Authorization" instead. Other than modifying the framework code, can you suggest a solution? Or consider it as a feature request? ### OAuth Provider (Twitter, Github, ..): Custom backend. ### OAuth Version: - [ ] Version 1 - [X] Version 2 ### OS (Please fill the version) : - [x] iOS : - [ ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [ ] Carthage - [ ] CocoaPods - [X] Manually ### Library version: - [ ] head - [X] v1.0.0 - [ ] v0.6 - [ ] other: (Please fill in the version you are using.) ### Xcode version: - [X] 8.0 (Swift 3.0) - [ ] 8.0 (Swift 2.3) - [ ] 7.3.1 - [ ] other: (Please fill in the version you are using.) - [ ] objective c
kerem 2026-03-03 16:46:38 +03:00
Author
Owner

@phimage commented on GitHub (Jan 11, 2017):

You can set into credential object a OAuthSwiftCredentialHeadersFactory
oauthSwift.client.credential.headersFactory=<your custom object>

get the token like this oauthSwift.client.credential.oauthToken or extends OAuthSwiftCredential

and in your custom object
return token.isEmpty ? [:] : ["X-Authorization": "Bearer \(token)"]

<!-- gh-comment-id:271823449 --> @phimage commented on GitHub (Jan 11, 2017): You can set into credential object a `OAuthSwiftCredentialHeadersFactory` `oauthSwift.client.credential.headersFactory=<your custom object>` get the token like this `oauthSwift.client.credential.oauthToken` or extends `OAuthSwiftCredential` and in your custom object `return token.isEmpty ? [:] : ["X-Authorization": "Bearer \(token)"]`
Author
Owner

@underbjerg commented on GitHub (Jan 11, 2017):

Perfect, just the answer I was looking for. I'll give it a try.

And thank you very much for the swift reply!

<!-- gh-comment-id:271835098 --> @underbjerg commented on GitHub (Jan 11, 2017): Perfect, just the answer I was looking for. I'll give it a try. And thank you very much for the swift reply!
Author
Owner

@phimage commented on GitHub (Jan 11, 2017):

new wiki page
https://github.com/OAuthSwift/OAuthSwift/wiki/Custom-authentication-headers

<!-- gh-comment-id:271838127 --> @phimage commented on GitHub (Jan 11, 2017): new wiki page https://github.com/OAuthSwift/OAuthSwift/wiki/Custom-authentication-headers
Author
Owner

@underbjerg commented on GitHub (Jan 11, 2017):

Excellent! Much appreciated :)

<!-- gh-comment-id:271848197 --> @underbjerg commented on GitHub (Jan 11, 2017): Excellent! Much appreciated :)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#203
No description provided.