diff --git a/internal/models/models.go b/internal/models/models.go index 8bb0bf195b35cec820155705fa3b374dec880ab0..605b5fae511d6549fd12fc11099d0132f24b12fc 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 71bd25d362bc53c44dfe69a0b40ca5f6d73d3408..a0ad6321f1b7e33c5b99254315c5bd63ba0b5ef3 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 e458f4ccd7f466d38138d58c83cb34e24b52f896..38978207178316a8ca581a3db18e2117a16b3fc4 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 b9cc6187b9cd0439fbda66b4daf338e407922fc0..a4c70c3891976227f8b7a7d901416c8912f04e32 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 cda761962974677d46da944f4f8c5cdadab048d8..c045043ceffe9b6c5569c8254f5997b2e4788bbf 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)