openshift/rangelreale-osin

Name: rangelreale-osin

Owner: OpenShift

Description: Golang OAuth2 server library

Forked from: RangelReale/osin

Created: 2016-07-03 01:09:51.0

Updated: 2018-01-31 18:52:01.0

Pushed: 2018-02-01 21:07:26.0

Homepage: null

Size: 218

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

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
rt (
"github.com/RangelReale/osin"
ex "github.com/RangelReale/osin/example" 


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

uthorization code endpoint
.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)


ccess token endpoint
.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)


.ListenAndServe(":14000", nil)
Example Access

Open in your web browser:

://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


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.