Skip to content

ains/niso

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NISO

An improved Golang OAuth2 server library

Go Report Card Build Status GoDoc

Introduction

NISO is an OAuth2 server library for the Go language, forked from OSIN. The project can be used build your own OAuth2 authentication service as per the speficiation at http://tools.ietf.org/html/rfc6749.

This fork offers the following advantages over OSIN:

  • Cleaner, simpler, majorly side-effect free API
  • Improved error messages and propagated error context using pkg/errors
  • Context support
  • Improved test coverage

Example Server

server := niso.NewServer(niso.NewServerConfig(), storage.NewExampleStorage())

// Authorization code endpoint
http.HandleFunc("/authorize", func(w http.ResponseWriter, r *http.Request) {
    resp, err := server.HandleHTTPAuthorizeRequest(
        r,
        func(ar *niso.AuthorizationRequest) (bool, error) {
            return true, nil
        },
    )
    if err != nil {
        log.Printf("Error handling authorize request %v", err)
    }

    niso.WriteJSONResponse(w, resp)
})

// Access token endpoint
http.HandleFunc("/token", func(w http.ResponseWriter, r *http.Request) {
    resp, err := server.HandleHTTPAccessRequest(
        r,
        func(ar *niso.AccessRequest) (bool, error) {
            return true, nil
        },
    )
    if err != nil {
        log.Printf("Error handling access request %v", err)
    }

    niso.WriteJSONResponse(w, resp)
})

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

About

An improved Golang OAuth2 server library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages