MCPcopy
hub / github.com/openshift/osin

github.com/openshift/osin @v1.0.1 sqlite

repository ↗ · DeepWiki ↗ · release v1.0.1 ↗
192 symbols 692 edges 32 files 87 documented · 45%
README

OSIN

GoDoc

Golang OAuth2 server library

OSIN is an OAuth2 server library for the Go language, as specified at http://tools.ietf.org/html/rfc6749 and http://tools.ietf.org/html/draft-ietf-oauth-v2-10.

It also includes support for PKCE, as specified at https://tools.ietf.org/html/rfc7636, which increases security for code-exchange flows for public OAuth clients.

Using it, you can build your own OAuth2 authentication service.

The library implements the majority of the specification, like authorization and token endpoints, and authorization code, implicit, resource owner and client credentials grant types.

Example Server

import (
    "github.com/RangelReale/osin"
    ex "github.com/RangelReale/osin/example" 
)

// ex.NewTestStorage implements the "osin.Storage" interface
server := osin.NewServer(osin.NewServerConfig(), ex.NewTestStorage())

// Authorization code endpoint
http.HandleFunc("/authorize", func(w http.ResponseWriter, r *http.Request) {
    resp := server.NewResponse()
    defer resp.Close()

    if ar := server.HandleAuthorizeRequest(resp, r); ar != nil {

        // HANDLE LOGIN PAGE HERE

        ar.Authorized = true
        server.FinishAuthorizeRequest(resp, r, ar)
    }
    osin.OutputJSON(resp, w, r)
})

// Access token endpoint
http.HandleFunc("/token", func(w http.ResponseWriter, r *http.Request) {
    resp := server.NewResponse()
    defer resp.Close()

    if ar := server.HandleAccessRequest(resp, r); ar != nil {
        ar.Authorized = true
        server.FinishAccessRequest(resp, r, ar)
    }
    osin.OutputJSON(resp, w, r)
})

http.ListenAndServe(":14000", nil)

Example Access

Open in your web browser:

http://localhost:14000/authorize?response_type=code&client_id=1234&redirect_uri=http%3A%2F%2Flocalhost%3A14000%2Fappauth%2Fcode

Storage backends

There is a mock available at example/teststorage.go which you can use as a guide for writing your own.

You might want to check out other implementations for common database management systems as well:

License

The code is licensed using "New BSD" license.

Author

Rangel Reale rangelreale@gmail.com

Changes

2014-06-25

  • BREAKING CHANGES:

    • Storage interface has 2 new methods, Clone and Close, to better support storages that need to clone / close in each connection (mgo)
    • Client was changed to be an interface instead of an struct. Because of that, the Storage interface also had to change, as interface is already a pointer.

    • HOW TO FIX YOUR CODE:

      • In your Storage, add a Clone function returning itself, and a do nothing Close.
      • In your Storage, replace all *osin.Client with osin.Client (remove the pointer reference)
      • If you used the osin.Client struct directly in your code, change it to osin.DefaultClient, which is a struct with the same fields that implements the interface.
      • Change all accesses using osin.Client to use the methods instead of the fields directly.
      • You MUST defer Response.Close in all your http handlers, otherwise some Storages may not clean correctly.
        resp := server.NewResponse()
        defer resp.Close()
        

Extension points exported contracts — how you extend this code

AccessTokenGen (Interface)
AccessTokenGen generates access tokens [3 implementers]
access.go
Client (Interface)
Client information [3 implementers]
client.go
Storage (Interface)
Storage interface [2 implementers]
storage.go
Logger (Interface)
Logger creates a formatted log event. NOTE: Log is meant for internal use only and may contain sensitive info. [2 implementers]
log.go
AuthorizeTokenGen (Interface)
AuthorizeTokenGen is the token generator interface [2 implementers]
authorize.go
ClientSecretMatcher (Interface)
ClientSecretMatcher is an optional interface clients can implement which allows them to be the one to determine if a sec [2 …
client.go

Core symbols most depended-on inside this repo

setErrorAndLog
called by 43
access.go
NewResponse
called by 33
server.go
Printf
called by 27
log.go
NewServer
called by 18
server.go
NewServerConfig
called by 18
config.go
Close
called by 17
response.go
Error
called by 16
urivalidate.go
GetRedirectUri
called by 15
client.go

Shape

Method 97
Function 57
Struct 24
TypeAlias 8
Interface 6

Languages

Go100%

Modules by API surface

access_test.go20 symbols
storage_test.go18 symbols
access.go18 symbols
example/teststorage.go14 symbols
client.go14 symbols
storage.go12 symbols
response.go11 symbols
authorize.go10 symbols
urivalidate.go7 symbols
example/openidconnect/openidconnect.go7 symbols
util.go6 symbols
config.go6 symbols

For agents

$ claude mcp add osin \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact