Skip to content

Commit

Permalink
change serviceValidation response (#3)
Browse files Browse the repository at this point in the history
* fix: response

* fix: response following real-world  sso response
  • Loading branch information
remove158 authored Feb 13, 2024
1 parent 33bd318 commit 2155022
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 29 deletions.
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,30 @@ The configuration is done by the following environment variables. (see [`docker

### GET /login

- Request
- Request

```sh
curl --request GET \
--url 'https://sso.piyaphat.com/login?service=https://www.google.com'
```

- Response 302 Found
- Response 302 Found

```js
// (on-success) 302 Location: https://www.google.com?ticket=86966dc5-2049-428f-88fe-2d78a5985d38
```

- Response 400 Bad Request
- Response 400 Bad Request

```json
{
"error": "Key: 'GetLoginRequest.Service' Error:Field validation for 'Service' failed on the 'required' tag"
"error": "Key: 'GetLoginRequest.Service' Error:Field validation for 'Service' failed on the 'required' tag"
}
```

### GET, POST /serviceValidation

- Request
- Request

```sh
curl --request POST \
Expand All @@ -65,29 +65,29 @@ curl --request POST \
--header 'DeeTicket: 1b50cf0d-ceed-46da-a672-4c61060ece8d'
```

- Response 200 (application/json)
- Response 200 (application/json)

```json
{
"uid":"6200000001",
"username":"Prayut-Chan-Angkhan",
"gecos":"Prayut-Chan-Angkhan",
"disable":false,
"roles":["student"],
"firstname":"Prayut",
"firstnameth":"Prayut",
"lastname":"Chan-Angkhan",
"lastnameth":"Chan-Angkhan",
"ouid":"6200000001",
"email":"6200000001@student.chula.ac.th"
"uid": "14c6c69f-21ca-4999-999c-423dde2515ad",
"username": "6200000021",
"gecos": "Prayut Chan-Angkhan, ENG",
"disable": false,
"roles": ["student"],
"firstname": "Prayut",
"firstnameth": "Prayut",
"lastname": "Chan-Angkhan",
"lastnameth": "Chan-Angkhan",
"ouid": "6200000021",
"email": "6200000021@student.chula.ac.th"
}
```

- Response 401 Unauthorized
- Response 401 Unauthorized

```json
{
"error": "ticket not found"
"error": "ticket not found"
}
```

Expand Down
10 changes: 6 additions & 4 deletions cmd/handlers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/url"

"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/google/wire"
"github.com/remove158/chula-sso/cmd/models"
"github.com/remove158/chula-sso/internal/services"
Expand Down Expand Up @@ -66,13 +67,14 @@ func (h *AuthHandler) PostLogin(ctx *gin.Context) {
}

func generateUserResponse(request models.PostLoginRequest) models.UserResponse {
username := fmt.Sprintf("%s-%s", request.FirstName, request.LastName)
uid := uuid.New().String()
email := fmt.Sprintf("%s@student.chula.ac.th", request.UID)
gecos := fmt.Sprintf("%s %s, ENG", request.FirstName, request.LastName)

return models.UserResponse{
UID: request.UID,
Username: username,
GECOS: username,
UID: uid,
Username: request.UID,
GECOS: gecos,
Disable: false,
Roles: []string{request.Roles},
FirstName: request.FirstName,
Expand Down
2 changes: 1 addition & 1 deletion cmd/handlers/auth_test.go
Original file line number Diff line number Diff line change
@@ -1 +1 @@
package handlers_test
package handlers_test
3 changes: 1 addition & 2 deletions internal/services/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"net/url"

"github.com/google/uuid"
"github.com/google/wire"
"github.com/kelseyhightower/envconfig"
"github.com/remove158/chula-sso/cmd/models"
Expand Down Expand Up @@ -41,7 +40,7 @@ func NewAuthService() *AuthService {
}

func (h *AuthService) PostLogin(user models.UserResponse) string {
ticket := uuid.New().String()
ticket := user.UID
h.cache[ticket] = user
return ticket
}
Expand Down
3 changes: 0 additions & 3 deletions vercel.json

This file was deleted.

0 comments on commit 2155022

Please sign in to comment.