mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-30 10:39:08 +02:00
Link account id with the external user store (#184)
* get account id from access token claim * use GetOrCreateAccountByUser and add test * correct account id claim * remove unused account * Idp manager interface * auth0 idp manager * use if instead of switch case * remove unnecessary lock * NewAuth0Manager * move idpmanager to its own package * update metadata when accountId is not supplied * update tests with idpmanager field * format * new idp manager and config support * validate if we fetch the interface before converting to string * split getJWTToken * improve tests * proper json fields and handle defer body close * fix ci lint notes * documentation and proper defer position * UpdateUserAppMetadata tests * update documentation * ManagerCredentials interface * Marshal and Unmarshal functions * fix tests * ManagerHelper and ManagerHTTPClient * further tests with mocking * rename package and custom http client * sync local packages * remove idp suffix
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
//Peers is a handler that returns peers of the account
|
||||
type Peers struct {
|
||||
accountManager *server.AccountManager
|
||||
authAudience string
|
||||
}
|
||||
|
||||
//PeerResponse is a response sent to the client
|
||||
@@ -29,9 +30,10 @@ type PeerRequest struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func NewPeers(accountManager *server.AccountManager) *Peers {
|
||||
func NewPeers(accountManager *server.AccountManager, authAudience string) *Peers {
|
||||
return &Peers{
|
||||
accountManager: accountManager,
|
||||
authAudience: authAudience,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,8 +64,9 @@ func (h *Peers) deletePeer(accountId string, peer *server.Peer, w http.ResponseW
|
||||
}
|
||||
|
||||
func (h *Peers) HandlePeer(w http.ResponseWriter, r *http.Request) {
|
||||
userId := extractUserIdFromRequestContext(r)
|
||||
account, err := h.accountManager.GetOrCreateAccountByUser(userId)
|
||||
userId, accountId := extractUserAndAccountIdFromRequestContext(r, h.authAudience)
|
||||
//new user -> create a new account
|
||||
account, err := h.accountManager.GetAccountByUserOrAccountId(userId, accountId)
|
||||
if err != nil {
|
||||
log.Errorf("failed getting account of a user %s: %v", userId, err)
|
||||
http.Redirect(w, r, "/", http.StatusInternalServerError)
|
||||
@@ -102,9 +105,9 @@ func (h *Peers) HandlePeer(w http.ResponseWriter, r *http.Request) {
|
||||
func (h *Peers) GetPeers(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
userId := extractUserIdFromRequestContext(r)
|
||||
userId, accountId := extractUserAndAccountIdFromRequestContext(r, h.authAudience)
|
||||
//new user -> create a new account
|
||||
account, err := h.accountManager.GetOrCreateAccountByUser(userId)
|
||||
account, err := h.accountManager.GetAccountByUserOrAccountId(userId, accountId)
|
||||
if err != nil {
|
||||
log.Errorf("failed getting account of a user %s: %v", userId, err)
|
||||
http.Redirect(w, r, "/", http.StatusInternalServerError)
|
||||
|
||||
Reference in New Issue
Block a user