Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hendrickson-tyler/swift-pkce

A simple Swift package for the PKCE OAuth 2.0 extension
https://github.com/hendrickson-tyler/swift-pkce

codechallenge codeverifier oauth2 pkce swift

Last synced: 2 months ago
JSON representation

A simple Swift package for the PKCE OAuth 2.0 extension

Awesome Lists containing this project

README

        

# Swift PKCE

Swift PKCE is a lightweight collection of commonly used, client-side code generations in an [OAuth 2.0 Authorization Code flow + PKCE](https://oauth.net/2/pkce/) implemented in Swift. Each function conforms to the [RFC 7636](https://datatracker.ietf.org/doc/html/rfc7636) protocol.

## Availability

Due to the dependency on [Apple CryptoKit](https://developer.apple.com/documentation/cryptokit), Swift PKCE is available to the following platforms:

iOS 13.0+\
iPadOS 13.0+\
macOS 10.15+\
Mac Catalyst 15.0+\
tvOS 15.0+\
watchOS 8.0+

## Usage

Import the Swift PKCE framework by adding it to the imports at the top of the file:

```swift
import PKCE
```

### Functions

**generateCodeVerifier**\
Generates a new, random code verifier with a specified length of characters.

```swift
func generateCodeVerifier(length: Int = 128) throws -> String {
```

**generateCodeChallenge**\
Generates a code challenge for a given code verifier.

```swift
func generateCodeChallenge(for: String) throws -> String
```

## Attribution

The original code for Swift PKCE was sourced from a [Bootstragram blog post](https://bootstragram.com/blog/oauth-pkce-swift-secure-code-verifiers-and-code-challenges/) written by [@dirtyhenry](https://github.com/dirtyhenry) and updated slightly.