https://github.com/marck100/oauth
OAuth allows you to perform authenticate requests using OAuth 1.0 protocol.
https://github.com/marck100/oauth
api authentication oauth oauth1 package swift4 twitter twitter-api
Last synced: 5 months ago
JSON representation
OAuth allows you to perform authenticate requests using OAuth 1.0 protocol.
- Host: GitHub
- URL: https://github.com/marck100/oauth
- Owner: Marck100
- Created: 2020-08-15T21:42:06.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-02-27T11:25:03.000Z (over 4 years ago)
- Last Synced: 2025-06-06T10:42:33.363Z (about 1 year ago)
- Topics: api, authentication, oauth, oauth1, package, swift4, twitter, twitter-api
- Language: Swift
- Homepage: https://marcopilloni.com
- Size: 64.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# OAuth
OAuth helps you authenticate your request with OAuth1 protocol.
It's very easy to use and needs basic information:
- consumerKey
- consumerSecretKey
...
and you can add parameters to the authorization field and more
## Let's start
1) Provide `consumerKey` and `consumerSecretKey`
```swift
OAuth.setConsumer(consumerKey: "xxx", consumerSecret: "xxx")
```
2) Provide `openURL`
```swift
OAuth.shared.openURL = { url in
...
}
```
3) Add callback support to your app in Targets>Your main app>Info>URL Types
4) Handle callback in your app
```swift
func scene(_ scene: UIScene, url: URL) {
/// This function return true if the passed url is OAuth callback
OAuth.shared.observeURL(url: url)
}
```
5) Login
```
OAuth.shared.login { success in
...
}
```
6) Generate your request
> Oauth generates most of the oauth parameters:
> - `oauth_signature_method`
> - `oauth_timestamp`
> - `oauth_nonce`
> - `oauth_version`
> - `oauth_signature`
But you can add extra parameters to the authorization header
```swift
let url = URL(string: "xxx")
let request = OAuth.shared.request(url, method: .post, oauthParameters: nil, parameters: nil)
```
7) Post your request
```swift
PostCenter.shared.post(request, completionHandler: completionHandler)
```
Oauth can also remember some key information like `token`, `tokenSecret` and `verifier` which will automatically be included in the authentication header as you update them.
```swift
OAuth.shared.setToken(token: "xxx", tokenSecret: "xxx")
OAuth.shared.setVerifier(verifier: "xxx")
```