Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hadiidbouk/simpleoauth2
A simple implementation of OAuth2 in Swift using Combine and AuthenticationServices (macOS and iOS).
https://github.com/hadiidbouk/simpleoauth2
authenticationservices combine oauth2 swift
Last synced: about 1 month ago
JSON representation
A simple implementation of OAuth2 in Swift using Combine and AuthenticationServices (macOS and iOS).
- Host: GitHub
- URL: https://github.com/hadiidbouk/simpleoauth2
- Owner: hadiidbouk
- License: mit
- Created: 2020-12-04T09:13:25.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2020-12-08T19:44:53.000Z (about 4 years ago)
- Last Synced: 2023-07-08T15:15:06.481Z (over 1 year ago)
- Topics: authenticationservices, combine, oauth2, swift
- Language: Swift
- Homepage:
- Size: 52.7 KB
- Stars: 28
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SimpleOAuth2
![workflow badge](https://github.com/hadiidbouk/SimpleOAuth2/workflows/build/badge.svg)
![version badge](https://img.shields.io/github/v/tag/hadiidbouk/SimpleOAuth2?label=Version)
![platform compatibility](https://img.shields.io/badge/Platform%20Compatibility-iOS%20%7C%20macOS-blue)A simple implementation of OAuth2 in Swift using Combine and AuthenticationServices.
The goal of this package is to make it as simple as possible :)
## Installation
You can add SimpleOAuth2 to an Xcode project by adding it as a package dependency.
1. From the **File** menu, select **Swift Packages › Add Package Dependency…**
2. Enter "https://github.com/hadiidbouk/SimpleOAuth2" into the package repository URL text field## Usage
You need to pass your client credentials to the signIn method using `OAuth2Request`
```swift
@State var cancellable: AnyCancellable?
let request: OAuth2Request = .init(authUrl: "",
tokenUrl: "",
clientId: "",
redirectUri: "",
clientSecret: "",
scopes: [])
Button(action: {
cancellable = auth.signIn(with: request)
.sink( receiveCompletion: { result in
switch result {
case .failure(let error):
print(error.localizedDescription)
default: break
}
}, receiveValue: { credentials in
credentials.save()
print(credentials)
})
}) {
Text("Login with GitLab")
}
```You can also use `save()` function to save the `OAuth2Credentials` instance to your `UserDefaults` and load the credentials using this static function `OAuth2Credentials.load()`.
## About this package
- It will never be published on Cocoapods neither on Carthage.
- Only Authorization Code flow supported since it's the recommended flow for native mobile apps.## Coming soon
- Adding refresh function for refreshing your token (if needed).