Skip to content

Commit 2155022

Browse files
authored
change serviceValidation response (#3)
* fix: response * fix: response following real-world sso response
1 parent 33bd318 commit 2155022

5 files changed

Lines changed: 27 additions & 29 deletions

File tree

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,30 @@ The configuration is done by the following environment variables. (see [`docker
3232

3333
### GET /login
3434

35-
- Request
35+
- Request
3636

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

42-
- Response 302 Found
42+
- Response 302 Found
4343

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

48-
- Response 400 Bad Request
48+
- Response 400 Bad Request
4949

5050
```json
5151
{
52-
"error": "Key: 'GetLoginRequest.Service' Error:Field validation for 'Service' failed on the 'required' tag"
52+
"error": "Key: 'GetLoginRequest.Service' Error:Field validation for 'Service' failed on the 'required' tag"
5353
}
5454
```
5555

5656
### GET, POST /serviceValidation
5757

58-
- Request
58+
- Request
5959

6060
```sh
6161
curl --request POST \
@@ -65,29 +65,29 @@ curl --request POST \
6565
--header 'DeeTicket: 1b50cf0d-ceed-46da-a672-4c61060ece8d'
6666
```
6767

68-
- Response 200 (application/json)
68+
- Response 200 (application/json)
6969

7070
```json
7171
{
72-
"uid":"6200000001",
73-
"username":"Prayut-Chan-Angkhan",
74-
"gecos":"Prayut-Chan-Angkhan",
75-
"disable":false,
76-
"roles":["student"],
77-
"firstname":"Prayut",
78-
"firstnameth":"Prayut",
79-
"lastname":"Chan-Angkhan",
80-
"lastnameth":"Chan-Angkhan",
81-
"ouid":"6200000001",
82-
"email":"6200000001@student.chula.ac.th"
72+
"uid": "14c6c69f-21ca-4999-999c-423dde2515ad",
73+
"username": "6200000021",
74+
"gecos": "Prayut Chan-Angkhan, ENG",
75+
"disable": false,
76+
"roles": ["student"],
77+
"firstname": "Prayut",
78+
"firstnameth": "Prayut",
79+
"lastname": "Chan-Angkhan",
80+
"lastnameth": "Chan-Angkhan",
81+
"ouid": "6200000021",
82+
"email": "6200000021@student.chula.ac.th"
8383
}
8484
```
8585

86-
- Response 401 Unauthorized
86+
- Response 401 Unauthorized
8787

8888
```json
8989
{
90-
"error": "ticket not found"
90+
"error": "ticket not found"
9191
}
9292
```
9393

cmd/handlers/auth.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/url"
77

88
"github.com/gin-gonic/gin"
9+
"github.com/google/uuid"
910
"github.com/google/wire"
1011
"github.com/remove158/chula-sso/cmd/models"
1112
"github.com/remove158/chula-sso/internal/services"
@@ -66,13 +67,14 @@ func (h *AuthHandler) PostLogin(ctx *gin.Context) {
6667
}
6768

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

7274
return models.UserResponse{
73-
UID: request.UID,
74-
Username: username,
75-
GECOS: username,
75+
UID: uid,
76+
Username: request.UID,
77+
GECOS: gecos,
7678
Disable: false,
7779
Roles: []string{request.Roles},
7880
FirstName: request.FirstName,

cmd/handlers/auth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
package handlers_test
1+
package handlers_test

internal/services/auth.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"net/url"
66

7-
"github.com/google/uuid"
87
"github.com/google/wire"
98
"github.com/kelseyhightower/envconfig"
109
"github.com/remove158/chula-sso/cmd/models"
@@ -41,7 +40,7 @@ func NewAuthService() *AuthService {
4140
}
4241

4342
func (h *AuthService) PostLogin(user models.UserResponse) string {
44-
ticket := uuid.New().String()
43+
ticket := user.UID
4544
h.cache[ticket] = user
4645
return ticket
4746
}

vercel.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)