Skip to content

Commit 1018b93

Browse files
authored
Merge pull request #826 from darshanasbg/self-service
Introduce user self service API
2 parents ae026b4 + 66316d6 commit 1018b93

File tree

16 files changed

+1674
-7
lines changed

16 files changed

+1674
-7
lines changed

api/user.yaml

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ tags:
2020
description: Operations related to user management
2121
- name: users-by-path
2222
description: Operations related to user management using hierarchical handle paths
23+
- name: self
24+
description: Self service operations related to the user
2325
- name: user-schemas
2426
description: Operations related to user type schema management
2527

@@ -689,6 +691,222 @@ paths:
689691
type: string
690692
example: "Internal server error"
691693

694+
/users/me:
695+
get:
696+
tags:
697+
- self
698+
summary: Get self user profile
699+
security:
700+
- OAuth2: []
701+
responses:
702+
"200":
703+
description: User details
704+
content:
705+
application/json:
706+
schema:
707+
$ref: '#/components/schemas/User'
708+
example:
709+
id: "e1b6ba6c-deb2-4d24-87b0-bbf79fa4487c"
710+
organizationUnit: "26eec421-f1bb-4deb-a5d3-9ab6554c2ae6"
711+
type: "employee"
712+
attributes:
713+
username: "alice.wu"
714+
firstname: "Alice"
715+
lastname: "Wu"
716+
717+
"401":
718+
description: Unauthorized - missing or invalid token
719+
content:
720+
application/json:
721+
schema:
722+
$ref: '#/components/schemas/Error'
723+
example:
724+
code: "USR-1018"
725+
message: "Authentication failed"
726+
description: "Invalid credentials provided"
727+
"404":
728+
description: Authenticated user not found
729+
content:
730+
application/json:
731+
schema:
732+
$ref: '#/components/schemas/Error'
733+
example:
734+
code: "USR-1003"
735+
message: "User not found"
736+
description: "The user with the specified id does not exist"
737+
"500":
738+
description: Internal server error
739+
content:
740+
application/json:
741+
schema:
742+
$ref: '#/components/schemas/Error'
743+
example:
744+
code: "USR-5000"
745+
message: "Internal server error"
746+
description: "An unexpected error occurred while processing the request"
747+
put:
748+
tags:
749+
- self
750+
summary: Update self user profile
751+
security:
752+
- OAuth2: []
753+
requestBody:
754+
required: true
755+
content:
756+
application/json:
757+
schema:
758+
$ref: '#/components/schemas/UpdateSelfUserRequest'
759+
example:
760+
attributes:
761+
username: "alice.wu"
762+
firstname: "Alice"
763+
lastname: "Wu"
764+
765+
responses:
766+
"200":
767+
description: User updated
768+
content:
769+
application/json:
770+
schema:
771+
$ref: '#/components/schemas/User'
772+
example:
773+
id: "e1b6ba6c-deb2-4d24-87b0-bbf79fa4487c"
774+
organizationUnit: "26eec421-f1bb-4deb-a5d3-9ab6554c2ae6"
775+
type: "employee"
776+
attributes:
777+
username: "alice.wu"
778+
firstname: "Alice"
779+
lastname: "Wu"
780+
781+
"400":
782+
description: Bad request
783+
content:
784+
application/json:
785+
schema:
786+
$ref: '#/components/schemas/Error'
787+
examples:
788+
invalid-request-format:
789+
summary: Invalid request format
790+
value:
791+
code: "USR-1001"
792+
message: "Invalid request format"
793+
description: "The request body is malformed or contains invalid data"
794+
schema-validation-failed:
795+
summary: Schema validation failed
796+
value:
797+
code: "USR-1019"
798+
message: "Schema validation failed"
799+
description: "User attributes do not conform to the required schema"
800+
user-schema-not-found:
801+
summary: User schema not found
802+
value:
803+
code: "USR-1021"
804+
message: "User schema not found"
805+
description: "The specified user schema does not exist"
806+
"401":
807+
description: Unauthorized - missing or invalid token
808+
content:
809+
application/json:
810+
schema:
811+
$ref: '#/components/schemas/Error'
812+
example:
813+
code: "USR-1018"
814+
message: "Authentication failed"
815+
description: "Invalid credentials provided"
816+
"404":
817+
description: Authenticated user not found
818+
content:
819+
application/json:
820+
schema:
821+
$ref: '#/components/schemas/Error'
822+
example:
823+
code: "USR-1003"
824+
message: "User not found"
825+
description: "The user with the specified id does not exist"
826+
"409":
827+
description: Conflict
828+
content:
829+
application/json:
830+
schema:
831+
$ref: '#/components/schemas/Error'
832+
example:
833+
code: "USR-1014"
834+
message: "Attribute conflict"
835+
description: "A user with the same unique attribute value already exists"
836+
"500":
837+
description: Internal server error
838+
content:
839+
application/json:
840+
schema:
841+
$ref: '#/components/schemas/Error'
842+
example:
843+
code: "USR-5000"
844+
message: "Internal server error"
845+
description: "An unexpected error occurred while processing the request"
846+
847+
/users/me/update-credentials:
848+
post:
849+
tags:
850+
- self
851+
summary: Update self user credentials
852+
security:
853+
- OAuth2: []
854+
requestBody:
855+
required: true
856+
content:
857+
application/json:
858+
schema:
859+
$ref: '#/components/schemas/UpdateSelfUserRequest'
860+
example:
861+
attributes:
862+
password: "n3wP@ssword!"
863+
responses:
864+
"204":
865+
description: Credentials updated
866+
"400":
867+
description: Bad request
868+
content:
869+
application/json:
870+
schema:
871+
$ref: '#/components/schemas/Error'
872+
examples:
873+
missing-credentials:
874+
summary: Missing credentials
875+
value:
876+
code: "USR-1017"
877+
message: "Missing credentials"
878+
description: "At least one credential field must be provided"
879+
"401":
880+
description: Unauthorized - missing or invalid token
881+
content:
882+
application/json:
883+
schema:
884+
$ref: '#/components/schemas/Error'
885+
example:
886+
code: "USR-1018"
887+
message: "Authentication failed"
888+
description: "Invalid credentials provided"
889+
"404":
890+
description: Authenticated user not found
891+
content:
892+
application/json:
893+
schema:
894+
$ref: '#/components/schemas/Error'
895+
example:
896+
code: "USR-1003"
897+
message: "User not found"
898+
description: "The user with the specified id does not exist"
899+
"500":
900+
description: Internal server error
901+
content:
902+
application/json:
903+
schema:
904+
$ref: '#/components/schemas/Error'
905+
example:
906+
code: "USR-5000"
907+
message: "Internal server error"
908+
description: "An unexpected error occurred while processing the request"
909+
692910
/user-schemas:
693911
get:
694912
tags:
@@ -1304,6 +1522,14 @@ components:
13041522
type: object
13051523
description: "User attributes"
13061524
additionalProperties: true
1525+
UpdateSelfUserRequest:
1526+
type: object
1527+
required: [attributes]
1528+
properties:
1529+
attributes:
1530+
type: object
1531+
description: "User attributes"
1532+
additionalProperties: true
13071533

13081534
UserSchema:
13091535
type: object

backend/internal/system/security/jwt_authenticator.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,13 @@ func extractClaim(claims map[string]interface{}, key string) string {
162162
}
163163

164164
// getRequiredScopes returns the required scopes for a given route path.
165-
func (h *jwtAuthenticator) getRequiredScopes(_ *http.Request) []string {
165+
func (h *jwtAuthenticator) getRequiredScopes(r *http.Request) []string {
166+
// User self service endpoints don't require scopes
167+
if strings.HasPrefix(r.URL.Path, "/users/me") {
168+
return []string{}
169+
}
170+
171+
// Default required scope for other endpoints
166172
return []string{"system"}
167173
}
168174

0 commit comments

Comments
 (0)