* fix #203 NetworkTransport race, with main-isolated variables (#206) Co-authored-by: wti <wti@users.noreply.github.com> * feat/auth: Authentication implementation (#205) * feat: added authentication * feat(auth): improvement to error handling * feat(auth): updated errors and tests in OAuthClientRegistrar * feat(auth): updated ci conformance package version * feat(auth): bumped node version * feat(auth): updated ci conformance step * feat(auth): improvement to Linux support * chore: added docc plugin * chore: added spi yml * chore: added documentation step to ci * chore: increased timeout for test from 5 to 10m --------- Co-authored-by: Paal Øye-Strømme <paal.o.eye@gmail.com> Co-authored-by: wti <wti@users.noreply.github.com> Co-authored-by: yehorsobko <yehorsobko@macpaw.com>
139 lines
3.6 KiB
Swift
139 lines
3.6 KiB
Swift
import Foundation
|
|
|
|
// MARK: - OAuth Grant Types
|
|
|
|
enum OAuthGrantTypeValue {
|
|
static let clientCredentials = "client_credentials"
|
|
static let authorizationCode = "authorization_code"
|
|
static let refreshToken = "refresh_token"
|
|
}
|
|
|
|
// MARK: - OAuth Parameter Names
|
|
|
|
enum OAuthParameterName {
|
|
static let grantType = "grant_type"
|
|
static let resource = "resource"
|
|
static let scope = "scope"
|
|
static let code = "code"
|
|
static let codeVerifier = "code_verifier"
|
|
static let codeChallenge = "code_challenge"
|
|
static let codeChallengeMethod = "code_challenge_method"
|
|
static let redirectURI = "redirect_uri"
|
|
static let responseType = "response_type"
|
|
static let clientID = "client_id"
|
|
static let clientSecret = "client_secret"
|
|
static let clientAssertion = "client_assertion"
|
|
static let clientAssertionType = "client_assertion_type"
|
|
static let refreshToken = "refresh_token"
|
|
static let state = "state"
|
|
}
|
|
|
|
// MARK: - OAuth Well-Known Paths
|
|
|
|
enum OAuthWellKnownPath {
|
|
static let protectedResource = "/.well-known/oauth-protected-resource"
|
|
static let authorizationServer = "/.well-known/oauth-authorization-server"
|
|
static let openIDConfiguration = "/.well-known/openid-configuration"
|
|
}
|
|
|
|
// MARK: - OAuth Token Type
|
|
|
|
enum OAuthTokenType {
|
|
static let bearer = "Bearer"
|
|
}
|
|
|
|
// MARK: - OAuth Code Challenge Method
|
|
|
|
enum OAuthCodeChallengeMethod {
|
|
static let s256 = "S256"
|
|
}
|
|
|
|
// MARK: - OAuth Token Endpoint Auth Method
|
|
|
|
enum OAuthTokenEndpointAuthMethod {
|
|
static let clientSecretBasic = "client_secret_basic"
|
|
static let clientSecretPost = "client_secret_post"
|
|
static let none = "none"
|
|
static let privateKeyJWT = "private_key_jwt"
|
|
}
|
|
|
|
// MARK: - URL Scheme
|
|
|
|
enum OAuthURLScheme {
|
|
static let http = "http"
|
|
static let https = "https"
|
|
}
|
|
|
|
// MARK: - Default Ports
|
|
|
|
enum OAuthDefaultPort {
|
|
static let http = 80
|
|
static let https = 443
|
|
}
|
|
|
|
// MARK: - Loopback Hosts
|
|
|
|
enum OAuthLoopbackHost {
|
|
static let localhost = "localhost"
|
|
static let ipv4 = "127.0.0.1"
|
|
static let ipv6 = "::1"
|
|
|
|
static func isLoopback(_ host: String) -> Bool {
|
|
host == localhost || host == ipv4 || host == ipv6
|
|
}
|
|
}
|
|
|
|
// MARK: - Token Expiry Skew
|
|
|
|
/// Clock skew tolerance applied when checking token expiry.
|
|
///
|
|
/// ``OAuthAccessToken/isExpired(now:skewSeconds:)`` treats a token as expired
|
|
/// when `now + skewSeconds >= expiresAt`, giving the client a safety margin to
|
|
/// refresh tokens before they actually expire on the server.
|
|
public enum OAuthTokenExpirySkew {
|
|
/// Default clock skew buffer: 30 seconds.
|
|
public static let defaultSeconds: TimeInterval = 30
|
|
}
|
|
|
|
// MARK: - JWT Claim Names
|
|
|
|
enum JWTClaimName {
|
|
static let algorithm = "alg"
|
|
static let type = "typ"
|
|
static let typeValue = "JWT"
|
|
static let issuer = "iss"
|
|
static let subject = "sub"
|
|
static let audience = "aud"
|
|
static let issuedAt = "iat"
|
|
static let expiration = "exp"
|
|
static let jwtID = "jti"
|
|
}
|
|
|
|
// MARK: - Client Assertion Type
|
|
|
|
enum OAuthClientAssertionType {
|
|
static let jwtBearer = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
|
|
}
|
|
|
|
// MARK: - HTTPHeaderName Extensions
|
|
|
|
extension HTTPHeaderName {
|
|
static let location = "Location"
|
|
}
|
|
|
|
// MARK: - ContentType Extensions
|
|
|
|
extension ContentType {
|
|
static let formURLEncoded = "application/x-www-form-urlencoded"
|
|
}
|
|
|
|
// MARK: - Data Base64URL Extension
|
|
|
|
extension Data {
|
|
func base64URLEncodedString() -> String {
|
|
base64EncodedString()
|
|
.replacingOccurrences(of: "+", with: "-")
|
|
.replacingOccurrences(of: "/", with: "_")
|
|
.replacingOccurrences(of: "=", with: "")
|
|
}
|
|
}
|