No description, website, or topics provided.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vendor/src/github.com/phuc0302
oauth_key
oauth_role
oauth_table
.gitignore
.gopmfile
LICENSE
README.md
authorization_grant.go
config.go
config_test.go
i_client.go
i_store.go
i_token.go
i_user.go
mongodb_client.go
mongodb_store.go
mongodb_store_test.go
mongodb_token.go
mongodb_token_test.go
mongodb_user.go
oauth_validation.go
oauth_validation_test.go
server.go
test_env.go
token_grant.go
token_grant_test.go

README.md

go-oauth2

OAuth2 Provider library written in Go

This is a ported project from OAuth2 Provider that had been written in Node.js with some additional features.

  • Pure implementation in GoLang.
  • Current implementation only supports password_flow & refresh_token_flow.
  • Use JWT.
  • Default buildin with MongoDB.
  • Allow to customize the server.

Example Server

package main

import (
	"fmt"

	"github.com/phuc0302/go-oauth2"
	"github.com/phuc0302/go-oauth2/oauth_key"
	"github.com/phuc0302/go-oauth2/oauth_role"
	"github.com/phuc0302/go-server"
	"github.com/phuc0302/go-server/util"
)

func main() {
	// Initialize server with sandbox mode enable and using MongoDB.
	oauth2.InitializeWithMongoDB(true, true)

	// Define handler
	f := func(c *server.RequestContext) {
		if s, ok := c.GetExtra(oauthKey.Context).(oauth2.OAuthContext); ok {
			c.OutputText(util.Status200(), fmt.Sprintf("Hello, your ID is: %s", s.User.UserID()))
		} else {
			panic(util.Status401())
		}
	}

	// Bind handler with HTTP GET
	oauth2.BindGet("/protected", oauthRole.All(), f)

	// Start server
	oauth2.Run()
}

Author

Phuc, Tran Huu phuc@fiisionstudio.com