A lightweight async Swift client for the public ORCID API, plus small helper types for OAuth URL construction and token exchange.
- SwiftPM
- Xcode 16.4+
Add to your Package.swift:
.package(url: "https://github.com/ezefranca/OrcidSwift.git", from: "1.0.0"),Then add OrcidSwift as a dependency of your target.
import OrcidSwift
let client = OrcidClient()
let record = try await client.fetchRecord(orcid: try OrcidID("0000-0002-1825-0097"))
print(record.orcidIdentifier?.uri ?? "")import OrcidSwift
let client = OrcidClient()
let works = try await client.fetchWorks(orcid: try OrcidID("0000-0002-1825-0097"))
print(works.group?.count ?? 0)import OrcidSwift
let client = OrcidClient(config: .init(environment: .production))
let url = try client.makeAuthorizeURL(
clientID: "YOUR_CLIENT_ID",
redirectURI: "yourapp://callback",
scopes: [.authenticate],
state: "csrf-state"
)
print(url)import OrcidSwift
let client = OrcidClient(config: .init(environment: .production))
let token = try await client.exchangeCodeForToken(
clientID: "YOUR_CLIENT_ID",
clientSecret: "YOUR_CLIENT_SECRET",
code: "AUTH_CODE",
redirectURI: "yourapp://callback"
)
print(token.accessToken)swift testIntegration tests are present but skipped unless explicitly enabled:
ORCIDSWIFT_RUN_INTEGRATION_TESTS=1 swift testMIT License. See LICENSE for details.