gin-server icon indicating copy to clipboard operation
gin-server copied to clipboard

Oauth APPs for users

Open moos3 opened this issue 6 years ago • 3 comments

So I'm working on an authentication system for users. I want to allow my users to create OAuth apps sorta like how GitHub does it in their developer section. Where the user can create the application, with register they get the client id and client secret. So I have functionality that will generate a client id and client secret with refresh/ revoke. What I'm wondering is how to take your example and make it database driven. Could you provide some guidance ?

moos3 avatar Jul 29 '19 18:07 moos3

You can refer to the use of redis storage: https://github.com/go-oauth2/redis

package main

import (
	"gopkg.in/go-oauth2/redis.v3"
	"gopkg.in/oauth2.v3/manage"
)

func main() {
	manager := manage.NewDefaultManager()
	
	// use redis token store
	manager.MapTokenStorage(redis.NewRedisStore(&redis.Options{
		Addr: "127.0.0.1:6379",
		DB: 15,
	}))
}

LyricTian avatar Jul 30 '19 00:07 LyricTian

We have currently a struct like this, this allow a user to create a new application to allow them to leverage our api. In our legacy PHP application, ClientID and ClientSecret are generated for the user.

type App struct {
        ID uuid.UUID
	Name string
	Slug string
	Description string
	ClientID string
	ClientSecret string
	CallbackURL string
	AppURL string
}

moos3 avatar Sep 03 '19 19:09 moos3

https://github.com/vgarvardt/go-oauth2-pg for ex. But you can also just implement the interfaces yourself too. With your own database logic. e.g.

	ClientStore interface {
	TokenStore interface {

jarlandre avatar Jan 18 '23 13:01 jarlandre