Contributing to oauth4s
Thanks for taking the time to contribute. This page covers what you need to build the project, run its tests, where common kinds of changes go, and how a release is cut.
Building
JDK 25 is required to build, and the build checks it when it loads: oauth4s-kyo compiles kyo 1.0, whose class
files are Java 25, and scalac has to load them. cs java --jvm 25 or brew install openjdk@25 gets you one; CI uses
the same.
What the build produces runs on JDK 17: -java-output-version 17 writes Java 17 class files and refuses any JDK API
newer than 17. The exception is oauth4s-kyo's runtime dependency on kyo, which needs 25 because kyo does.
Every published module compiles on Versions.scala3 (3.9, the LTS) in project/Dependencies.scala. it is the
exception on purpose: it compiles on Versions.scala3Next (3.10) against the library compiled by 3.9.
sbt compile # compile everything
sbt "testOnly *" # run the tests of every published module
sbt "it/testOnly *" # the flows over real HTTP, the README's examples and the recipes, on the next Scala
sbt "scalafmtCheckAll; scalafmtSbtCheck; it/scalafmtCheckAll" # verify formatting, as CI does
sbt "examples/runMain oauth4s.examples.CatsEffectExample"sbt 2 takes several tasks as one quoted string separated by ;. It also caches test runs and replays a cached run's
log, so a repeated test with unchanged inputs runs nothing; testOnly * is what CI uses, and changing the filter
forces a real run.
To run one module's tests:
sbt core/test
sbt "it/testOnly oauth4s.it.OidcFlowItSpec"
sbt "jwt/testOnly oauth4s.jwt.JwtSpec"Publishing credentials live in ~/.sbt/sonatype_credentials, outside the repository. A checkout without the file
builds and tests exactly the same; the build only adds the credentials when the file is there.
Project layout
| Path | What lives there |
|---|---|
core |
the protocol model, the client, discovery, the errors, the built-in JSON codec, and the Effect, HttpClient and JsonCodec SPIs |
jwt |
JWT parsing, verification and signing, JWK, JWKS and the cached remote key source |
oidc |
OidcClient: ID token validation, UserInfo, logout |
providers |
one object per provider behind Provider[F] |
runtime/cats, runtime/zio, runtime/kyo, runtime/rapid |
given Effect[F] per runtime |
http/jdk, http/http4s, http/sttp |
HttpClient[F] per client |
json/circe, json/zio, json/jsoniter |
given JsonCodec and the decoder bridge per JSON library |
testkit |
StubHttpClient, TestIssuer, FakeAuthorizationServer; its tests hold the suites the modules above share |
it |
an OpenID Connect login over real HTTP, and the examples of the README and the recipes, compiled on the next Scala release and run |
examples |
one runnable main per runtime, each against FakeAuthorizationServer |
benchmarks |
JMH benchmarks of parsing and ID token verification |
core has no dependencies and must keep having none. A new JSON library, runtime or HTTP client is a new module and a
new given, never a dependency of core.
What a change looks like
- A new protocol value is an opaque type in
values.scalawith anapplyand avalueextension. If it can be wrong, it is checked there, not where it is used. - A new error code is a case of
ErrorCodeand an entry in itsregisteredlist. - A new option is a field and a
withXmethod on the builder it belongs to —OAuthClientConfig,AuthorizationOptions,OidcConfig,JwtValidation— never a new constructor parameter of a public case class. - A new flow is a method on the
OAuthClienttrait and its implementation inOAuthClientImpl. Every response document has onefromJsonthat returnsEither[OAuthError, ...]. - A new provider is an object in
providerswithconfig,apply,fromand a pureprofile(json), a case inProvidersSpec, and a row in the README table. Check the endpoints against the provider's documentation, not against another library. If the provider deviates in a way the knobs ofOAuthClientConfigcannot express, add a knob, not a special case in the client. - A new runtime is a module with a
given Effect[F], anXInstancestrait and object, and a spec that extendsRuntimeSuite[F]. - A new HTTP client is a module with an
HttpClient[F]and a spec that extendsHttpClientSuite[F]. - A new JSON library is a module with a
given JsonCodec, a bridge from its decoders toJsonDecoder, its codecs forJsonandTokenResponse, and a spec that extendsJsonCodecSuite.
Testing
Tests are scalatest, AnyWordSpec and Matchers, with names that describe the behaviour and the reason for it. core
is tested on scala.util.Try with a clock moved by hand (ManualTime) and a recording HTTP client, so no test sleeps
and none depends on a runtime.
The suite of a runtime, a JSON bridge or an HTTP client is the shared one: if the behaviour you are adding belongs to
the SPI and not to one implementation, it goes in RuntimeSuite, JsonCodecSuite or HttpClientSuite, so every
implementation is held to it.
Documentation
- Every Scala block in README.md and RECIPES.md is copied from an example under
it/src/test/scala/oauth4s/it/docs, which theitmodule compiles with the same warnings as the library.DocsItSpecfails on a block that matches no example, whitespace aside, and on a dependency line whose version is not the onebuild.sbtpublishes.RecipesItSpecruns the recipes that do something, againstFakeAuthorizationServer. Change the example and the block together. - There is no documentation site in this repository. oss.sendline.now/oauth4s is built in its own repository from README.md and the files it links: every H2 section of the README is a page, and a heading that is renamed there has to be renamed in that site's configuration. Link between the documents with relative paths.
- The logos in
logos/are generated by the same repository (tools/brand.mjs). Do not edit them by hand. - A fact about a provider — an endpoint, a scope, the shape of a response — comes from the provider's documentation, and COMPATIBILITY.md says when it was last checked. Update the date when you check again.
- Numbers in BENCHMARKS.md come from
sbt "benchmarks/Jmh/run"; rerun it when parsing or verification changes.
The code carries no comments and no scaladoc. Where the logic is subtle enough to need explaining, the explanation
belongs in README.md, DESIGN.md or COMPATIBILITY.md, not in a comment
nobody reading the docs will find. The examples under it/…/docs are the exception: their comments are the captions
of the README.
Formatting
scalafmt runs from the build; maxColumn = 170, align.preset = most. Do not reformat files you did not touch. The
house style beyond what scalafmt enforces — colon bodies, import blocks ordered by line length, if ... then — is what
the existing code already does; match it.
Cutting a release
- Update
versioninbuild.sbtandCHANGELOG.md. sbt "testOnly *",sbt "it/testOnly *"andsbt "scalafmtCheckAll; scalafmtSbtCheck; it/scalafmtCheckAll".sbt publishSigned(stages to Sonatype), thensonatypeReleaseAllonce the staging repository is validated.- Tag the commit
vX.Y.Zand publish the GitHub release with the changelog section.
mimaPreviousArtifacts is empty until the first release; after that, add the released version to
binaryCompatibleWith and let mimaReportBinaryIssues guard the public API.