Skip to content

Package oidc aims to provide an easy-to-use way to do OpenID Connect ID token based authentication in your Go web app.

License

Notifications You must be signed in to change notification settings

ugent-library/oidc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Reference

ugent-library/oidc

Package oidc aims to provide an easy-to-use way to do OpenID Connect ID token based authentication in your Go web app.

Install

go get -u github.com/ugent-library/oidc

Examples

    oidcAuth, _ := oidc.NewAuth(context.TODO(), oidc.Config{
		URL:          config.OIDC.URL,
		ClientID:     config.OIDC.ID,
		ClientSecret: config.OIDC.Secret,
		RedirectURL:  baseURL + "/auth/oidc",
		CookieName:   "oidc.state",
		CookieSecret: []byte(config.OIDC.CookieSecret),
	})

    http.HandleFunc("/login", func(w http.ResponseWriter, r *http.Request) {
        err := oidcAuth.BeginAuth(w, r)
        if err != nil {
            http.Error(w, "auth failed", http.StatusInternalServerError)
        }
    })

    http.HandleFunc("/auth/oidc", func(w http.ResponseWriter, r *http.Request) {
        claims := oidc.Claims{}
    	err := h.oidcAuth.CompleteAuth(c.Res, c.Req, &claims)
        if err != nil {
            http.Error(w, "auth failed", http.StatusInternalServerError)
    		return
    	}

        // handle successful login
    })

About

Package oidc aims to provide an easy-to-use way to do OpenID Connect ID token based authentication in your Go web app.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages