diff --git a/views.go b/views.go index 6311a6b..69ed3e6 100644 --- a/views.go +++ b/views.go @@ -112,16 +112,20 @@ func ServiceValidate(c echo.Context) error { result := User{} ticket := c.FormValue("ticket") - err := DatabaseConnection.QueryRow(` - SELECT - id - , username - , given_name - , family_name - FROM osf_osfuser + var queryString = ` + SELECT DISTINCT + osf_guid._id, + osf_osfuser.username, + osf_osfuser.given_name, + osf_osfuser.family_name + From osf_guid + LEFT JOIN django_content_type + ON django_content_type.model = 'osfuser' + JOIN osf_osfuser + ON django_content_type.id = osf_guid.content_type_id AND object_id = osf_osfuser.id WHERE username = $1 OR $1 = ANY(emails) - `, ticket).Scan(&result.Id, &result.Username, &result.GivenName, &result.Username) - + ` + err := DatabaseConnection.QueryRow(queryString, ticket).Scan(&result.Id, &result.Username, &result.GivenName, &result.FamilyName) if err != nil { if err != sql.ErrNoRows { panic(err) @@ -129,6 +133,7 @@ func ServiceValidate(c echo.Context) error { fmt.Println("User", ticket, "not found.") return c.NoContent(http.StatusNotFound) } + fmt.Println("User found: username =", result.Username, ", guid =", result.Id,) response := ServiceResponse{ Xmlns: "http://www.yale.edu/tp/cas", @@ -140,7 +145,6 @@ func ServiceValidate(c echo.Context) error { AccessToken: result.Id, UserName: result.Username, } - return c.XML(http.StatusOK, response) } @@ -152,17 +156,23 @@ func OAuth(c echo.Context) error { tokenId := strings.Replace(c.Request().Header.Get("Authorization"), "Bearer ", "", 1) - err := DatabaseConnection.QueryRow(` - SELECT - user.id - , user.given_name - , user.family_name - , token.scopes - FROM osf_apioauth2personaltoken AS token - JOIN osf_osfuser AS user ON user.id = token.owner_id - WHERE token_id = $1 - `, tokenId).Scan(&result.Id, &result.Username, &result.GivenName, scopes) - + var queryString = ` + SELECT DISTINCT + osf_guid._id, + osf_osfuser.username, + osf_osfuser.given_name, + osf_osfuser.family_name, + osf_apioauth2personaltoken.scopes + FROM osf_guid + LEFT JOIN django_content_type + ON django_content_type.model = 'osfuser' + JOIN osf_osfuser + ON django_content_type.id = osf_guid.content_type_id AND object_id = osf_osfuser.id + JOIN osf_apioauth2personaltoken + ON osf_osfuser.id = osf_apioauth2personaltoken.owner_id + WHERE osf_apioauth2personaltoken.token_id = $1 + ` + err := DatabaseConnection.QueryRow(queryString, tokenId).Scan(&result.Id, &result.Username, &result.GivenName, &result.FamilyName, &scopes) if err != nil { if err != sql.ErrNoRows { panic(err) @@ -170,6 +180,7 @@ func OAuth(c echo.Context) error { fmt.Println("Access token", tokenId, "not found") return c.NoContent(http.StatusNotFound) } + fmt.Println("User found for token: username =", result.Username, ", guid =", result.Id,) return c.JSON(200, OAuthResponse{ Id: result.Id,