开源软件名称(OpenSource Name):openshift/osin开源软件地址(OpenSource Url):https://github.com/openshift/osin开源编程语言(OpenSource Language):Go 99.7%开源软件介绍(OpenSource Introduction):OSINGolang OAuth2 server libraryOSIN 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 Serverimport (
"github.com/openshift/osin"
ex "github.com/openshift/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 AccessOpen in your web browser:
Storage backendsThere 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: LicenseThe code is licensed using "New BSD" license. AuthorRangel Reale rangelreale@gmail.com Changes2019-05-13
2014-06-25
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论