diff --git a/Dockerfile b/Dockerfile index 9379e8952d4..962eed554e1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -118,6 +118,43 @@ RUN gem install bundler -v 2.3.26 && \ apt-get update && \ apt-get install -y --no-install-recommends ruby-dev=1:2.7+2 +# swift + +RUN apt-get -y install libncurses5 clang + +RUN apt-get -y install libxml2 + +RUN \ + curl https://download.swift.org/swift-5.9.2-release/ubuntu1804/swift-5.9.2-RELEASE/swift-5.9.2-RELEASE-ubuntu18.04.tar.gz -o swift.tar.gz &&\ + tar xzf swift.tar.gz && \ + mv swift-5.9.2-RELEASE-ubuntu18.04 /usr/share/swift && \ + export PATH=/usr/share/swift/usr/bin:$PATH && \ + swift -v + +ENV PATH /usr/share/swift/usr/bin:$PATH + +# Install swift-openapi-generator +RUN git clone https://github.com/apple/swift-openapi-generator.git \ +&& cd swift-openapi-generator \ +&& swift build \ +&& ln -s $(pwd)/.build/debug/swift-openapi-generator /usr/local/bin/swift-openapi-generator \ +&& swift-openapi-generator --help + +# Install Homebrew +RUN git clone https://github.com/Homebrew/brew /home/linuxbrew/Homebrew \ + && mkdir -p /home/linuxbrew/bin \ + && ln -s /home/linuxbrew/Homebrew/bin/brew /home/linuxbrew/bin/ \ + && export PATH="/home/linuxbrew/bin:$PATH" + +# Export Homebrew binary directory to PATH +ENV PATH /home/linuxbrew/bin:$PATH + +# Disable automatic updates +ENV HOMEBREW_NO_AUTO_UPDATE=1 + +# Install SourceDocs to generate swift client documentation +RUN brew install sourcedocs + ADD go.mod go.mod ADD go.sum go.sum RUN go build -o /usr/local/bin/ory github.com/ory/cli diff --git a/contrib/clients/swift/CustomDateTranscoder.swift b/contrib/clients/swift/CustomDateTranscoder.swift new file mode 100644 index 00000000000..3f5b2813cb5 --- /dev/null +++ b/contrib/clients/swift/CustomDateTranscoder.swift @@ -0,0 +1,26 @@ +import Foundation +import OpenAPIRuntime + +/// A transcoder for dates encoded as an ISO-8601 string (in RFC 3339 format). Allows date with internet date time and fractional seconds. +public struct CustomDateTranscoder: DateTranscoder, @unchecked Sendable { + + /// Creates and returns an ISO 8601 formatted string representation of the specified date. + public func encode(_ date: Date) throws -> String { + let formatter = ISO8601DateFormatter() + formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds] + return formatter.string(from: date) } + + /// Creates and returns a date object from the specified ISO 8601 formatted string representation. + public func decode(_ dateString: String) throws -> Date { + let formatter = ISO8601DateFormatter() + formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds] + print(dateString) + guard let date = formatter.date(from: dateString) else { + throw DecodingError.dataCorrupted( + .init(codingPath: [], debugDescription: "Expected date string to be ISO8601-formatted.") + ) + } + return date + } +} + diff --git a/contrib/clients/swift/Package.swift b/contrib/clients/swift/Package.swift new file mode 100644 index 00000000000..938db653d94 --- /dev/null +++ b/contrib/clients/swift/Package.swift @@ -0,0 +1,23 @@ +// swift-tools-version: 5.9 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + + +let package = Package( + name: "OryClient", + platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .visionOS(.v1)], + dependencies: [ + .package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"), + .package(url: "https://github.com/apple/swift-openapi-urlsession", from: "1.0.0") + ], + targets: [ + .executableTarget( + name: "OryClient", + dependencies: [ + .product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"), + .product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession") + ] + ) + ] +) diff --git a/contrib/clients/swift/README.md b/contrib/clients/swift/README.md new file mode 100644 index 00000000000..4cebfc35fb6 --- /dev/null +++ b/contrib/clients/swift/README.md @@ -0,0 +1,45 @@ +# Ory Swift SDK + +Documentation for all public and administrative Ory APIs. Administrative APIs can only be accessed with a valid Personal Access Token. Public APIs are mostly used in browsers. + + +This package is atomatically generated by [Swift OpenAPI Generator](https://github.com/apple/swift-openapi-generator) + +## Installation + +Add the package dependency in your Package.swift: + +```swift +.package(url: "https://github.com/ory/client-swift", from: "1.0.0"), +``` + +Next, in your target, add OryClient to your dependencies: + +```swift +.target(name: "MyTarget", dependencies: [ + .product(name: "OryCLient", package: "OryClient"), +]), +``` + + + +## Usage + +When creating an Ory client, use CustomDateTranscoder to support date with internet date time and fractional seconds. + +```swift +import OpenAPIRuntime +import OpenAPIURLSession +import Foundation + +let serverURL = URL(string: "https://{your-project-slug}.projects.oryapis.com") +let customDateTranscoder = CustomDateTranscoder() +let transport = URLSessionTransport() + +let oryClient = Client(serverURL: serverURL!, + configuration: Configuration(dateTranscoder: customDateTranscoder), + transport: transport) + +let response = try await oryClient.createNativeLoginFlow() +print(try response.ok) +``` \ No newline at end of file diff --git a/contrib/clients/swift/openapi.yaml b/contrib/clients/swift/openapi.yaml new file mode 100644 index 00000000000..9b3629474c5 --- /dev/null +++ b/contrib/clients/swift/openapi.yaml @@ -0,0 +1,19337 @@ +openapi: 3.0.3 +info: + contact: + email: support@ory.sh + name: API Support + description: | + Documentation for all public and administrative Ory APIs. Administrative APIs can only be accessed + with a valid Personal Access Token. Public APIs are mostly used in browsers. + license: + name: Apache 2.0 + url: https://www.apache.org/licenses/LICENSE-2.0.html + termsOfService: /ptos + title: Ory APIs + version: v1.5.1 +servers: +- url: "https://{project}.projects.oryapis.com/" + variables: + project: + default: playground + description: Project slug as provided by the Ory Console. +tags: +- description: APIs for managing identities. + name: identity +- description: "Endpoints used by frontend applications (e.g. Single-Page-App, Native\ + \ Apps, Server Apps, ...) to manage a user's own profile." + name: frontend +- description: APIs for managing email and SMS message delivery. + name: courier +- description: Server Metadata provides relevant information about the running server. + Only available when self-hosting this service. + name: metadata +paths: + /.well-known/jwks.json: + get: + description: |- + This endpoint returns JSON Web Keys required to verifying OpenID Connect ID Tokens and, + if enabled, OAuth 2.0 JWT Access Tokens. This endpoint can be used with client libraries like + [node-jwks-rsa](https://github.com/auth0/node-jwks-rsa) among others. + operationId: discoverJsonWebKeys + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/jsonWebKeySet' + description: jsonWebKeySet + default: + content: + application/json: + schema: + $ref: '#/components/schemas/errorOAuth2' + description: errorOAuth2 + summary: Discover Well-Known JSON Web Keys + tags: + - wellknown + /.well-known/openid-configuration: + get: + description: |- + A mechanism for an OpenID Connect Relying Party to discover the End-User's OpenID Provider and obtain information needed to interact with it, including its OAuth 2.0 endpoint locations. + + Popular libraries for OpenID Connect clients include oidc-client-js (JavaScript), go-oidc (Golang), and others. + For a full list of clients go here: https://openid.net/developers/certified/ + operationId: discoverOidcConfiguration + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/oidcConfiguration' + description: oidcConfiguration + default: + content: + application/json: + schema: + $ref: '#/components/schemas/errorOAuth2' + description: errorOAuth2 + summary: OpenID Connect Discovery + tags: + - oidc + /.well-known/ory/webauthn.js: + get: + description: |- + This endpoint provides JavaScript which is needed in order to perform WebAuthn login and registration. + + If you are building a JavaScript Browser App (e.g. in ReactJS or AngularJS) you will need to load this file: + + ```html +