fix incorrect gui refresh if theme is changed
implement custom clientstore add new Password page if password is set force entering password to successfully receive the token add a new unsafe api call for init call only
This commit is contained in:
		
							
								
								
									
										56
									
								
								apiGo/api/oauth/CustomClientStore.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								apiGo/api/oauth/CustomClientStore.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,56 @@
 | 
			
		||||
package oauth
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"gopkg.in/oauth2.v3"
 | 
			
		||||
	"openmediacenter/apiGo/database/settings"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type CustomClientStore struct {
 | 
			
		||||
	oauth2.ClientStore
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type CustomClientInfo struct {
 | 
			
		||||
	oauth2.ClientInfo
 | 
			
		||||
	ID     string
 | 
			
		||||
	Secret string
 | 
			
		||||
	Domain string
 | 
			
		||||
	UserID string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewCustomStore() oauth2.ClientStore {
 | 
			
		||||
	s := new(CustomClientStore)
 | 
			
		||||
	return s
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *CustomClientStore) GetByID(id string) (oauth2.ClientInfo, error) {
 | 
			
		||||
	password := settings.GetPassword()
 | 
			
		||||
	if password == nil {
 | 
			
		||||
		defaultpassword := "openmediacenter"
 | 
			
		||||
		password = &defaultpassword
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	clientinfo := CustomClientInfo{
 | 
			
		||||
		ID:     "openmediacenter",
 | 
			
		||||
		Secret: *password,
 | 
			
		||||
		Domain: "http://localhost:8081",
 | 
			
		||||
		UserID: "openmediacenter",
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &clientinfo, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *CustomClientInfo) GetID() string {
 | 
			
		||||
	return a.ID
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *CustomClientInfo) GetSecret() string {
 | 
			
		||||
	return a.Secret
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *CustomClientInfo) GetDomain() string {
 | 
			
		||||
	return a.Domain
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *CustomClientInfo) GetUserID() string {
 | 
			
		||||
	return a.UserID
 | 
			
		||||
}
 | 
			
		||||
@@ -3,7 +3,7 @@ package oauth
 | 
			
		||||
import (
 | 
			
		||||
	"gopkg.in/oauth2.v3/errors"
 | 
			
		||||
	"gopkg.in/oauth2.v3/manage"
 | 
			
		||||
	"gopkg.in/oauth2.v3/models"
 | 
			
		||||
	//"gopkg.in/oauth2.v3/models"
 | 
			
		||||
	"gopkg.in/oauth2.v3/server"
 | 
			
		||||
	"gopkg.in/oauth2.v3/store"
 | 
			
		||||
	"log"
 | 
			
		||||
@@ -17,15 +17,19 @@ func InitOAuth() {
 | 
			
		||||
	// token store
 | 
			
		||||
	manager.MustTokenStorage(store.NewMemoryTokenStore())
 | 
			
		||||
 | 
			
		||||
	clientStore := store.NewClientStore()
 | 
			
		||||
	// todo we need to check here if a password is enabled in db -- when yes set it here!
 | 
			
		||||
	clientStore.Set("openmediacenter", &models.Client{
 | 
			
		||||
		ID:     "openmediacenter",
 | 
			
		||||
		Secret: "openmediacenter",
 | 
			
		||||
		Domain: "http://localhost:8081",
 | 
			
		||||
	})
 | 
			
		||||
	//clientStore := store.NewClientStore()
 | 
			
		||||
	//// todo we need to check here if a password is enabled in db -- when yes set it here!
 | 
			
		||||
	//clientStore.Set("openmediacenter", &models.Client{
 | 
			
		||||
	//	ID:     "openmediacenter",
 | 
			
		||||
	//	Secret: "openmediacenter",
 | 
			
		||||
	//	Domain: "http://localhost:8081",
 | 
			
		||||
	//})
 | 
			
		||||
	//
 | 
			
		||||
	//manager.MapClientStorage(clientStore)
 | 
			
		||||
 | 
			
		||||
	strtest := NewCustomStore()
 | 
			
		||||
	manager.MapClientStorage(strtest)
 | 
			
		||||
 | 
			
		||||
	manager.MapClientStorage(clientStore)
 | 
			
		||||
	srv = server.NewServer(server.NewConfig(), manager)
 | 
			
		||||
	srv.SetClientInfoHandler(server.ClientFormHandler)
 | 
			
		||||
	manager.SetRefreshTokenCfg(manage.DefaultRefreshTokenCfg)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user