oauth2

package module
v0.12.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 5 Imported by: 1

README

Golang OAuth 2.0 Server Implement IDX-OAUTH2

GitHub stars GitHub forks GitHub issues Go Reference ReportCard License

About

This project is for who want to build your own OAUTH2 and OIDC server with golang,It use for oauth2 to support OIDC and device code grant type. Build your own repository to store users and clients authorizations. the repository provided in this module is just a sample. and it is not recommended to use it in production.

Features

OAuth2.0 Server Implementation, Support Grant Types:

Quick Start

1. Download and Install go module
go get -u -v github.com/wingfeng/idx-oauth2
2. create your main function

you can find the example in ./example/mainInMem.go

import oauth2 "github.com/wingfeng/idx-oauth2"

func main() {

	config := conf.DefaultConfig()
	config.Scheme = "http"

	router := gin.Default()

	store := memstore.NewStore([]byte("secret"))

	sessionHandler := sessions.Sessions("mysession", store)
	router.LoadHTMLGlob("../static/*.html")
	router.Static("/img", "../static/img")
	tokenService, jwks := buildTokenService(config)
	clientRepo := buildClientRepo()
	authRepo := repo.NewInMemoryAuthorizeRepository()

	consentRepo := repo.NewInMemoryConsentRepository()

	userService := &service.DefaultUserService{
		UserRepository: buildUserRepo(),
	}
	tenant := oauth2.NewTenant(config, clientRepo, authRepo, consentRepo, userService, tokenService, jwks)

	tenant.InitOAuth2Router(router, sessionHandler)

	address := fmt.Sprintf("%s:%d", "", 9097)
	router.Run(address)
	}

3. test it with the example client

you can find the example client in ./example/client/main.go it is the sample client for oauth2 from https://github.com/go-oauth2/oauth2, open another terminal to run followed command

    cd ./example/client
    go run .

Open your browser with http://localhost:9000/

4. test it other ways

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tenant

type Tenant struct {
	ClientService    service.ClientService
	AuthorizeService service.AuthorizeService
	TokenService     service.TokenService
	UserService      service.UserService
	ConsentService   service.ConsentService
	Config           *conf.Config

	//allow app to customize login logout index
	IndexCtrl  endpoint.IIndexController
	LoginCtrl  endpoint.ILoginController
	LogoutCtrl endpoint.ILogoutController
	// contains filtered or unexported fields
}

func NewTenant

func NewTenant(config *conf.Config,

	clientRepo repo.ClientRepository,
	authRepo repo.AuthorizationRepository,
	consentRepo repo.ConsentRepository,
	userService service.UserService,
	tokenService service.TokenService,
	jwks *conf.JWKS,
) *Tenant

func (*Tenant) InitOAuth2Router

func (s *Tenant) InitOAuth2Router(router *gin.Engine, SessionHandler func(ctx *gin.Context))

Directories

Path Synopsis
client command
gorm command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL