From 593b0860b9761c63f12f6eb3d3a23f3f72504d54 Mon Sep 17 00:00:00 2001
From: Alexis Poyen <apoyen@mail.apoyen.fr>
Date: Tue, 31 Mar 2020 14:41:20 +0200
Subject: [PATCH] Feat : add AuthType field to technical user

---
 internal/models/models.go               | 2 +-
 internal/rootmux/rootmux_test.go        | 6 ++----
 miscellaneous/keycloak/keycloak-down.sh | 0
 pkg/auth/auth.go                        | 1 +
 pkg/auth/inmemory.go                    | 1 +
 pkg/auth/oauth2.go                      | 1 +
 6 files changed, 6 insertions(+), 5 deletions(-)
 mode change 100644 => 100755 miscellaneous/keycloak/keycloak-down.sh

diff --git a/internal/models/models.go b/internal/models/models.go
index 8bb0bf1..605b5fa 100644
--- a/internal/models/models.go
+++ b/internal/models/models.go
@@ -9,8 +9,8 @@ import (
 	"strings"
 	"time"
 
+	"forge.grandlyon.com/apoyen/sdk-go/pkg/auth"
 	"github.com/jinzhu/gorm"
-	"github.com/nicolaspernoud/vestibule/pkg/auth"
 
 	// Needed for sqlite
 
diff --git a/internal/rootmux/rootmux_test.go b/internal/rootmux/rootmux_test.go
index 71bd25d..a0ad632 100644
--- a/internal/rootmux/rootmux_test.go
+++ b/internal/rootmux/rootmux_test.go
@@ -11,11 +11,11 @@ import (
 	"regexp"
 	"testing"
 
+	"forge.grandlyon.com/apoyen/sdk-go/pkg/tester"
 	"github.com/nicolaspernoud/vestibule/pkg/auth"
-	"github.com/nicolaspernoud/vestibule/pkg/tester"
 	"github.com/nicolaspernoud/vestibule/pkg/tokens"
 
-	"github.com/nicolaspernoud/vestibule/internal/mocks"
+	"forge.grandlyon.com/apoyen/sdk-go/internal/mocks"
 )
 
 var (
@@ -115,8 +115,6 @@ func UnLoggedTests(t *testing.T) {
 	do("POST", "/Login", noH, `{"login": "unknownuser","password": "password"}`, http.StatusForbidden, `user not found`)
 	// Do a in memory login with a known user but bad password
 	do("POST", "/Login", noH, `{"login": "admin","password": "badpassword"}`, http.StatusForbidden, `user not found`)
-	// Try to get a share token (must fail)
-	do("POST", "/api/common/Share", noH, `{"sharedfor":"guest","url":"userdav.vestibule.io/mydata/test.txt","lifespan":1,"readonly":true}`, 401, "error extracting token")
 }
 
 /**
diff --git a/miscellaneous/keycloak/keycloak-down.sh b/miscellaneous/keycloak/keycloak-down.sh
old mode 100644
new mode 100755
diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go
index e458f4c..3897820 100644
--- a/pkg/auth/auth.go
+++ b/pkg/auth/auth.go
@@ -26,6 +26,7 @@ const (
 type User struct {
 	ID           string   `json:"id,omitempty"`
 	Login        string   `json:"login"`
+	AuthType     string   `json:authType`
 	DisplayName  string   `json:"displayName,omitempty"`
 	Roles        []string `json:"memberOf"`
 	IsAdmin      bool     `json:"isAdmin,omitempty"`
diff --git a/pkg/auth/inmemory.go b/pkg/auth/inmemory.go
index b9cc618..a4c70c3 100644
--- a/pkg/auth/inmemory.go
+++ b/pkg/auth/inmemory.go
@@ -40,6 +40,7 @@ func (m Manager) HandleInMemoryLogin(w http.ResponseWriter, r *http.Request) {
 		log.Logger.Printf("| %v | Login failure | %v | %v", sentUser.Login, r.RemoteAddr, log.GetCityAndCountryFromRequest(r))
 		return
 	}
+	user.AuthType = "local"
 	// Store the user in cookie
 	// Store only the relevant info
 	// Generate
diff --git a/pkg/auth/oauth2.go b/pkg/auth/oauth2.go
index cda7619..c045043 100644
--- a/pkg/auth/oauth2.go
+++ b/pkg/auth/oauth2.go
@@ -112,6 +112,7 @@ func (m Manager) HandleOAuth2Callback() http.Handler {
 		for key, role := range user.Roles {
 			user.Roles[key] = strings.TrimPrefix(strings.Split(role, ",")[0], "CN=")
 		}
+		user.AuthType = "OAuth2"
 		// Store the user in cookie
 		// Generate
 		xsrfToken, err := common.GenerateRandomString(16)
-- 
GitLab