Skip to content

ezefranca/OrcidSwift

Repository files navigation

OrcidSwift

A lightweight async Swift client for the public ORCID API, plus small helper types for OAuth URL construction and token exchange.

Requirements

  • SwiftPM
  • Xcode 16.4+

Installation

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.

Usage

Fetch a public record

import OrcidSwift

let client = OrcidClient()
let record = try await client.fetchRecord(orcid: try OrcidID("0000-0002-1825-0097"))
print(record.orcidIdentifier?.uri ?? "")

Fetch works

import OrcidSwift

let client = OrcidClient()
let works = try await client.fetchWorks(orcid: try OrcidID("0000-0002-1825-0097"))
print(works.group?.count ?? 0)

Build an OAuth authorize URL

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)

Exchange code for token

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)

Tests

Unit tests

swift test

Integration tests (real internet)

Integration tests are present but skipped unless explicitly enabled:

ORCIDSWIFT_RUN_INTEGRATION_TESTS=1 swift test

License

MIT License. See LICENSE for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages