openshift/osin: Building an OAuth2 service in Go
Golang OAuth2 server library
At a glance
- What is it?
- OSIN is a Go library for implementing OAuth2 authorization services, including authorization and token endpoints, several grant types, and PKCE. It suits developers who need direct control over HTTP routing, authorization decisions, storage, and response handling.
- Who is it for?
- Adopt OSIN when the application needs a custom Go OAuth2 service with explicit storage and HTTP-handler control. Do not choose it when an off-the-shelf identity provider would remove more integration work.
- Can I use it commercially?
- Yes. BSD-3-Clause is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 67 days ago.
- What is it written in?
- Mainly Go, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on October 23, 2026, and from our analysis. They are not legal advice.
Star history
- openshift/osin1,934 ★ · +1
| Repository | 2026-10-16 | 2026-10-23 |
|---|---|---|
| openshift/osin | 1.9k | 1.9k |
1 Stars in the last 7 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
OSIN's custom OAuth2 service boundary
OSIN addresses a specific problem: providing an OAuth2 server inside an application written in Go rather than delegating authorization to a separate identity service. Its intended users are backend developers who need to decide how clients are registered, where requests are routed, what credentials are persisted, and when an authorization request should be approved. The README says the library implements most of RFC 6749 and also supports PKCE as described in RFC 7636.
The supported surface includes authorization and token endpoints, the authorization code, implicit, resource owner, and client credentials grant types. PKCE is particularly relevant to public OAuth clients because the README describes it as increasing security for code-exchange flows. This makes OSIN a protocol toolkit, but not a packaged login product. The example still has a comment reserved for application-specific login handling, so authentication policy remains with the integrating service.
This boundary matters during adoption. OSIN can reduce the work involved in validating OAuth requests and generating protocol responses, but it does not provide a documented user account system, login interface, administration console, or policy engine. Those concerns must exist elsewhere in the application or remain outside the project.
Authorization and token request flow
OSIN divides an OAuth2 service across two application-owned HTTP endpoints. The `/authorize` handler creates a `server.NewResponse()`, passes the request to `server.HandleAuthorizeRequest`, and calls `server.FinishAuthorizeRequest` when the authorization decision is complete. The README example then writes the response with `osin.OutputJSON`.
The `/token` handler follows a parallel path. It first calls `server.HandleAccessRequest`. If that method returns a request object, the application marks it authorized and passes it to `server.FinishAccessRequest`. This separation makes the request parsing, application decision, final protocol response, and HTTP serialization visible in code.
A storage implementation connects this flow to persistent or in-memory client, authorization, and token data. The repository includes `example/teststorage.go` as a mock and guidance for implementing `osin.Storage`. Separate storage projects are listed for PostgreSQL, MongoDB, RethinkDB, DynamoDB, Couchbase, MySQL, and Redis, but those projects are outside this repository and their current compatibility cannot be confirmed here.
Both handlers defer `resp.Close`. That detail is not cosmetic in the library's history. The README's 2014 breaking-change notes say some storage implementations need `Clone` and `Close` to clean resources correctly for each connection. Omitting cleanup can therefore affect storage behavior, especially in implementations that hold connection-specific resources.
Repository setup and the documented first flow
The README does not provide installation instructions such as a `go get`, `go install`, or dependency-management command. It presents the import path `github.com/openshift/osin`, while `go.mod` identifies the same module and declares Go 1.15. The repository includes example directories, and the Makefile defines a `build-examples` target that builds each immediate subdirectory under `./example` with `go build -race`.
From an already obtained checkout, the documented build entry point is:
make build-examplesThis target builds the example directories and emits one `building` line for each directory. Because the README does not give package-specific launch commands, the only browser request explicitly documented by the project is the authorization URL below. It expects the example server to be listening on port `14000`.
http://localhost:14000/authorize?response_type=code&client_id=1234&redirect_uri=http%3A%2F%2Flocalhost%3A14000%2Fappauth%2FcodeThe query selects the authorization code response type, client ID `1234`, and the shown redirect URI. This is a protocol-flow example, not a complete production setup. A real application must provide its client registration and login decision at the marked handler location.
The essential server construction shown in the README is:
server := osin.NewServer(osin.NewServerConfig(), ex.NewTestStorage())`ex.NewTestStorage` is the repository's mock storage. It is useful as a reference implementation, but adopting OSIN requires confirming whether it meets production persistence, concurrency, cleanup, and recovery requirements.
Storage contracts and implementation burden
The `Storage` interface is the main extension boundary in OSIN. The README tells implementers to use `example/teststorage.go` as a guide, while its change history records a breaking update that added `Clone` and `Close`. Implementations also had to change client handling from a pointer-based structure to the `osin.Client` interface, with `osin.DefaultClient` available as a concrete implementation.
Those changes reveal that storage is not a passive key-value adapter. It participates in the request lifecycle and may need to create or release resources. The application must also return responses through the server API and serialize them with `osin.OutputJSON`. Skipping the deferred `Close` call leaves cleanup up to unrelated behavior and is specifically identified by the project as unsafe for some storages.
The linked database implementations show that persistence has been treated as a separate concern. OSIN itself does not, based on the repository information supplied, establish which external storage projects remain compatible with the current module version. The presence of example code is evidence that an integration pattern exists, not evidence that every linked backend is production-ready. Engineers evaluating a database adapter would need to inspect that adapter's own source, tests, and maintenance record.
OSIN compared with client-side OAuth2 code
A concrete alternative direction is represented in this repository by `golang.org/x/oauth2`. It appears in `go.mod`, and the repository contains an `example/goauth2client` directory. The difference in approach is that OSIN exposes server-side operations such as `HandleAuthorizeRequest`, `FinishAuthorizeRequest`, `HandleAccessRequest`, and `FinishAccessRequest`. A client-side OAuth2 library is intended to obtain and use access tokens rather than host the authorization and token endpoints.
That means the alternatives address opposite sides of an OAuth2 deployment. Adding a client library does not replace an authorization server, while embedding OSIN does not replace the client logic used by protected Go applications. A team that only needs outbound access to an existing OAuth2 provider should inspect the client-side route first. A team that must issue and validate its own authorization artifacts needs server-side components, and the supplied information confirms OSIN's role there.
No separate hosted identity provider or full OAuth2 server framework is identified in the repository information, so this article does not assign unverified maintenance or capability claims to such products. The practical comparison available here is architectural: server construction in Go through OSIN versus client-side token consumption through a dependency that does not replace those server handlers.
Maintenance, compatibility, and upgrade exposure
The repository is not archived, and its last push was on 2026-08-17. However, it has no GitHub releases, so there is no release-based upgrade record to cite. The README's explicit change log is sparse. Its newest listed change is dated 2019-05-13 and changes example imports from `github.com/RangelReale/osin` to `github.com/openshift/osin`. The earlier 2014 entry documents substantive breaking changes to the storage interface and client model.
`go.mod` declares Go 1.15 and pins several older dependency versions, including `github.com/dgrijalva/jwt-go v3.2.0+incompatible`, `gopkg.in/square/go-jose.v1 v1.1.2`, and a 2020-dated `golang.org/x/oauth2` pseudo-version. The repository also includes a `vendor` directory and references OpenShift build machinery. These facts matter when integrating OSIN because consumers must evaluate compatibility with the intended Go version and with their own dependency graph.
The code is licensed under the BSD-3-Clause license, described in the README as the New BSD license. That permits use and modification under the license's stated conditions, but organizations still need to review the actual `LICENSE` file and their compliance obligations. The absence of GitHub releases also means an upgrade may involve repository changes rather than a documented semantic-release sequence.
Editorial conclusion
Adopt OSIN when the application needs a custom Go OAuth2 service with explicit storage and HTTP-handler control. Do not choose it when an off-the-shelf identity provider would remove more integration work. Verify the required grants, storage behavior, response cleanup, token format, and compatibility with your current Go toolchain first, because OSIN provides protocol building blocks rather than a complete identity product.
Frequently asked questions
Which OAuth2 grant types does openshift/osin support?
The README lists authorization code, implicit, resource owner, and client credentials grant types. It also states that the library implements most of RFC 6749 and supports PKCE.
Does openshift/osin include a ready-made user login system?
No ready-made login system is documented. The example server leaves a place marked `HANDLE LOGIN PAGE HERE`, so the integrating application must decide how to authenticate and authorize the user.
Why should an openshift/osin HTTP handler close its Response?
The project's change history says some storage implementations need `Clone` and `Close` to clean resources correctly for each connection. The examples therefore defer `resp.Close` in both authorization and token handlers.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/openshift-osin)Star history chart for your README
[](https://hysenlabs.com/projects/openshift-osin)Was this useful?