All Projects → maxzerbini → Oauth

maxzerbini / Oauth

Licence: mit
OAuth 2.0 Authorization Server & Authorization Middleware for Gin-Gonic

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Oauth

Grant
OAuth Proxy
Stars: ✭ 3,509 (+5652.46%)
Mutual labels:  middleware, oauth
Dashport
Local and OAuth authentication middleware for Deno
Stars: ✭ 131 (+114.75%)
Mutual labels:  middleware, oauth
L Passport
Koa middleware and api sdk for wechat oauth, qq oauth, baidu oauth and weibo oauth
Stars: ✭ 52 (-14.75%)
Mutual labels:  oauth
Helmet
Help secure Express apps with various HTTP headers
Stars: ✭ 8,648 (+14077.05%)
Mutual labels:  middleware
Koa Useragent
Koa user-agent middleware
Stars: ✭ 54 (-11.48%)
Mutual labels:  middleware
Condor Framework
Framework for building GRPC services in Node JS. Include middleware, and more.
Stars: ✭ 52 (-14.75%)
Mutual labels:  middleware
Netcore Postgres Oauth Boiler
A basic .NET Core website boilerplate using PostgreSQL for storage, Adminer for db management, Let's Encrypt for SSL certificates and NGINX for routing.
Stars: ✭ 57 (-6.56%)
Mutual labels:  oauth
Api server boilerplate
typescript express board boilerplate using routing controller
Stars: ✭ 52 (-14.75%)
Mutual labels:  oauth
React Native Learning Resources
Collection of some good resources for react-native ✨ 🔥 💥
Stars: ✭ 61 (+0%)
Mutual labels:  oauth
Gin Glog
Gin middleware to use glog
Stars: ✭ 53 (-13.11%)
Mutual labels:  middleware
Http Proxy Middleware
⚡ The one-liner node.js http-proxy middleware for connect, express and browser-sync
Stars: ✭ 8,730 (+14211.48%)
Mutual labels:  middleware
Redux Electron Ipc
Redux Electron IPC Middleware
Stars: ✭ 54 (-11.48%)
Mutual labels:  middleware
Idtoken Verifier
Lightweight RSA JWT verification
Stars: ✭ 52 (-14.75%)
Mutual labels:  oauth
Momi
Monadic middleware
Stars: ✭ 57 (-6.56%)
Mutual labels:  middleware
Laravel Oauth
Social OAuth authentication for Laravel 5 & 6. Drivers: Facebook, Twitter, Google, LinkedIn, Github, Bitbucket.
Stars: ✭ 52 (-14.75%)
Mutual labels:  oauth
Websocket
🧬 WebSocket middleware for Fiber
Stars: ✭ 59 (-3.28%)
Mutual labels:  middleware
Django Channels React Multiplayer
turn based strategy game using django channels, redux, and react hooks
Stars: ✭ 52 (-14.75%)
Mutual labels:  middleware
Rainbow
An Express router middleware for RESTful API base on file path.
Stars: ✭ 53 (-13.11%)
Mutual labels:  middleware
Dragon
⚡A powerful HTTP router and URL matcher for building Deno web servers.
Stars: ✭ 56 (-8.2%)
Mutual labels:  middleware
Mailchimp Api 3.0 Php
A feature rich object-oriented PHP library for interacting with MailChimp's API v3 💌🐵
Stars: ✭ 61 (+0%)
Mutual labels:  oauth

oauth middleware

OAuth 2.0 Authorization Server & Authorization Middleware for Gin-Gonic

This library offers an OAuth 2.0 Authorization Server based on Gin-Gonic and an Authorization Middleware usable in Resource Servers developed with Gin-Gonic.

Build status

Build Status

Authorization Server

The Authorization Server is implemented by the struct OAuthBearerServer that manages two grant types of authorizations (password and client_credentials). This Authorization Server is made to provide an authorization token usable for consuming resources API.

Password grant type

OAuthBearerServer supports the password grant type, allowing the token generation for username / password credentials.

Client Credentials grant type

OAuthBearerServer supports the client_credentials grant type, allowing the token generation for client_id / client_secret credentials.

Authorization Code and Implicit grant type

These grant types are currently partially supported implementing AuthorizationCodeVerifier interface. The method ValidateCode is called during the phase two of the authorization_code grant type evalutations.

Refresh token grant type

If authorization token will expire, the client can regenerate the token calling the authorization server and using the refresh_token grant type.

Authorization Middleware

The Gin-Gonic middleware BearerAuthentication intercepts the resource server calls and authorizes only resource requests containing a valid bearer token.

Token Formatter

Authorization Server crypts the token using the Token Formatter and Authorization Middleware decrypts the token using the same Token Formatter. This library contains a default implementation of the formatter interface called SHA256RC4TokenSecureFormatter based on the algorithms SHA256 and RC4. Programmers can develop their Token Formatter implementing the interface TokenSecureFormatter and this is really recommended before publishing the API in a production environment.

Credentials Verifier

The interface CredentialsVerifier defines the hooks called during the token generation process. The methods are called in this order:

  • ValidateUser() or ValidateClient() called first for credentials verification
  • AddClaims() used for add information to the token that will be encrypted
  • StoreTokenId() called after the token generation but before the response, programmers can use this method for storing the generated Ids
  • AddProperties() used for add clear information to the response

There is another method in the CredentialsVerifier interface that is involved during the refresh token process. In this case the methods are called in this order:

  • ValidateTokenId() called first for TokenId verification, the method receives the TokenId related to the token associated to the refresh token
  • AddClaims() used for add information to the token that will be encrypted
  • StoreTokenId() called after the token regeneration but before the response, programmers can use this method for storing the generated Ids
  • AddProperties() used for add clear information to the response

Authorization Server usage example

This snippet shows how to create an authorization server

func main() {
	router := gin.New()
	router.Use(gin.Recovery())
	router.Use(gin.Logger())

    s := oauth.NewOAuthBearerServer(
		"mySecretKey-10101",
		time.Second*120,
		&TestUserVerifier{},
		nil)
	router.POST("/token", s.UserCredentials)
	router.POST("/auth", s.ClientCredentials)
	
	router.Run(":9090")
}

See /test/authserver/main.go for the full example.

Authorization Middleware usage example

This snippet shows how to use the middleware

    authorized := router.Group("/")
	// use the Bearer Athentication middleware
	authorized.Use(oauth.Authorize("mySecretKey-10101", nil))

	authorized.GET("/customers", GetCustomers)
	authorized.GET("/customers/:id/orders", GetOrders)

See /test/resourceserver/main.go for the full example.

Note that the authorization server and the authorization middleware are both using the same token formatter and the same secret key for encryption/decryption.

Note

This master branch introduces breaking changes in the interface CredentialsVerifier methods ValidateUser, ValidateClient and AddClaims. Refer to v1 branch for the previous implementation. Updated server implementation in v3 due to go.uuid library change.

Reference

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].