GoAuth provides helper libraries for authentication in Go, with a focus on API services. It covers OAuth 2.0, JWT, TLS client authentication and Basic Auth. A primary goal is to be able to create a *http.Client
from a single JSON application definition.
Major features include:
- The base
goauth
package is designed to provide a single file format for handling configuration of all methods of authentication, including BasicAuth, OAuth 2.0, and JWT credentials. The primary use case is to have a single JSON definition of multiple applications for multiple services which can be used to generate token and API requests. It works withgoauth/endpoints
to add endpoints for known services. - Create
*http.Client
for multiple API services. UseNewClient()
functions to create*http.Client
structs for services not supported inoauth2
likeaha
,metabase
,ringcentral
,salesforce
,visa
, etc. Generating*http.Client
structs is especially useful for using with Swagger Codegen auto-generated SDKs to support different auth models. - Create OAuth 2.0 authorization code token from the command line (for test purposes). No website is needed.
- Retrieve canonical user information via helper libraries to retrieve canonical user information from services. The SCIM user schema is used for a canonical user model. This may be replaced/augmented by OIDC
userinfo
in the future. - Transparently handle OAuth 2 for multiple services, e.g. a website that supports Google and Facebook auth. This is demoed in grokify/beego-oauth2-demo
$ go get github.com/grokify/goauth
ClientUtil
structs satisfy the interface having SetClient()
and GetSCIMUser()
functions.
import(
"github.com/grokify/goauth/google"
)
// googleOAuth2HTTPClient is *http.Client from Golang OAuth2
googleClientUtil := google.NewClientUtil(googleOAuth2HTTPClient)
scimuser, err := googleClientUtil.GetSCIMUser()
import(
"github.com/grokify/goauth/facebook"
)
// fbOAuth2HTTPClient is *http.Client from Golang OAuth2
fbClientUtil := facebook.NewClientUtil(fbOAuth2HTTPClient)
scimuser, err := fbClientUtil.GetSCIMUser()
import(
"github.com/grokify/goauth/ringcentral"
)
// rcOAuth2HTTPClient is *http.Client from Golang OAuth2
rcClientUtil := ringcentral.NewClientUtil(rcOAuth2HTTPClient)
scimuser, err := rcClientUtil.GetSCIMUser()
This repo comes with a generic test OAuth 2 redirect page which can be used with headless (no-UI) apps. To use this test URL, configure the following URL to be your OAuth 2 redirect URI. This will write the Authorization Code in the HTMl which you can then copy and paste into your own app.
The URL is located here:
See the following repo for a Beego-based demo app: