Skip to content

Commit 1822226

Browse files
Merge pull request #13 from Authing/feat/user-auth-permission
feat:add user auth permission
2 parents 8a91dd2 + 2ed5218 commit 1822226

9 files changed

+124
-2
lines changed

authentication/authentication_client.go

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ func (client *AuthenticationClient) GetNewAccessTokenByRefreshToken(refreshToken
332332
return string(resp.Body), err
333333
}
334334

335-
func (client *AuthenticationClient) IntrospectToken(token string) (*dto.IntrospectTokenResult, error) {
335+
func (client *AuthenticationClient) IntrospectToken(token string) (*dto.TokenIntrospectResponse, error) {
336336
url := client.options.AppHost + fmt.Sprintf("/%s/token/introspection", client.options.Protocol)
337337
header := map[string]string{
338338
"Content-Type": "application/x-www-form-urlencoded",
@@ -357,7 +357,7 @@ func (client *AuthenticationClient) IntrospectToken(token string) (*dto.Introspe
357357
ReqDto: body,
358358
})
359359
println(string(resp.Body))
360-
var response dto.IntrospectTokenResult
360+
var response dto.TokenIntrospectResponse
361361
if err != nil {
362362
return nil, err
363363
}
@@ -2165,3 +2165,42 @@ func (client *AuthenticationClient) GetUserAuthorizedResourcesList() *dto.GetUse
21652165
}
21662166

21672167
// ==== AUTO GENERATED AUTHENTICATION METHODS END ====
2168+
/*
2169+
* @summary 获取用户指定资源权限列表
2170+
* @description 获取用户指定资源的权限列表,用户获取某个应用下指定资源的权限列表。
2171+
* @returns GetUserAuthResourcePermissionListRespDto
2172+
*/
2173+
func (client *AuthenticationClient) getUserAuthResourcePermissionList(reqDto *dto.GetUserAuthResourcePermissionListDto) *dto.GetUserAuthResourcePermissionListRespDto {
2174+
b, err := client.SendHttpRequest("/api/v3/get-user-auth-resource-permission-list", fasthttp.MethodPost, reqDto)
2175+
var response dto.GetUserAuthResourcePermissionListRespDto
2176+
if err != nil {
2177+
fmt.Println(err)
2178+
return nil
2179+
}
2180+
err = json.Unmarshal(b, &response)
2181+
if err != nil {
2182+
fmt.Println(err)
2183+
return nil
2184+
}
2185+
return &response
2186+
}
2187+
2188+
/*
2189+
* @summary 获取用户授权资源的结构列表
2190+
* @description 获取用户授权的资源列表,用户获取某个应用下的某个资源所授权的结构列表,通过不同的资源类型返回对应资源的授权列表。
2191+
* @returns GetUserAuthResourceStructRespDto
2192+
*/
2193+
func (client *AuthenticationClient) getUserAuthResourceStruct(reqDto *dto.GetUserAuthResourceStructDto) *dto.GetUserAuthResourceStructRespDto {
2194+
b, err := client.SendHttpRequest("/api/v3/get-user-auth-resource-struct", fasthttp.MethodPost, reqDto)
2195+
var response dto.GetUserAuthResourceStructRespDto
2196+
if err != nil {
2197+
fmt.Println(err)
2198+
return nil
2199+
}
2200+
err = json.Unmarshal(b, &response)
2201+
if err != nil {
2202+
fmt.Println(err)
2203+
return nil
2204+
}
2205+
return &response
2206+
}

authentication/authentication_client_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,36 @@ func TestAuthenticationClient_GetUserAuthorizedResourcesList(t *testing.T) {
229229
fmt.Println(response)
230230

231231
}
232+
233+
func TestAuthenticationClient_GetUserAuthResourcePermissionList(t *testing.T) {
234+
235+
resp := authenticationClient.SignInByUsernamePassword(
236+
"4", "4", dto.SignInOptionsDto{})
237+
fmt.Println(resp.StatusCode, resp.RequestId, resp.Message)
238+
fmt.Println(resp.Data.AccessToken)
239+
authenticationClient.SetAccessToken(resp.Data.AccessToken)
240+
241+
request := dto.GetUserAuthResourcePermissionListDto{
242+
Resources: []string{"r1", "r2", "r3/1", "r3/1/11", "r3/1/11/111", "r3/2"},
243+
}
244+
response := authenticationClient.getUserAuthResourcePermissionList(&request)
245+
fmt.Println(response)
246+
247+
}
248+
249+
func TestAuthenticationClient_GetUserAuthResourceStruct(t *testing.T) {
250+
251+
resp := authenticationClient.SignInByUsernamePassword(
252+
"4", "4", dto.SignInOptionsDto{})
253+
fmt.Println(resp.StatusCode, resp.RequestId, resp.Message)
254+
fmt.Println(resp.Data.AccessToken)
255+
authenticationClient.SetAccessToken(resp.Data.AccessToken)
256+
257+
request := dto.GetUserAuthResourceStructDto{
258+
Resource: "r3",
259+
}
260+
261+
response := authenticationClient.getUserAuthResourceStruct(&request)
262+
fmt.Println(response)
263+
264+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package dto
2+
3+
type GetUserAuthResourcePermissionList struct {
4+
NamespaceCode string `json:"namespaceCode"`
5+
Actions []string `json:"actions"`
6+
Resource string `json:"resource"`
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package dto
2+
3+
type GetUserAuthResourcePermissionListDataDto struct {
4+
PermissionList []GetUserAuthResourcePermissionList `json:"permissionList"`
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package dto
2+
3+
type GetUserAuthResourcePermissionListDto struct {
4+
Resources []string `json:"resources"`
5+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package dto
2+
3+
type GetUserAuthResourcePermissionListRespDto struct {
4+
StatusCode int `json:"statusCode"`
5+
Message string `json:"message"`
6+
ApiCode int `json:"apiCode,omitempty"`
7+
RequestId string `json:"requestId,omitempty"`
8+
Data GetUserAuthResourcePermissionListDataDto `json:"data"`
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package dto
2+
3+
type GetUserAuthResourceStructDataDto struct {
4+
NamespaceCode string `json:"namespaceCode"`
5+
ResourceCode string `json:"resourceCode"`
6+
ResourceType string `json:"resourceType"`
7+
StrResourceAuthAction StrResourceAuthAction `json:"strResourceAuthAction,omitempty"`
8+
ArrResourceAuthAction ArrResourceAuthAction `json:"arrResourceAuthAction,omitempty"`
9+
TreeResourceAuthAction TreeResourceAuthAction `json:"treeResourceAuthAction,omitempty"`
10+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package dto
2+
3+
type GetUserAuthResourceStructDto struct {
4+
Resource string `json:"resource"`
5+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package dto
2+
3+
type GetUserAuthResourceStructRespDto struct {
4+
StatusCode int `json:"statusCode"`
5+
Message string `json:"message"`
6+
ApiCode int `json:"apiCode,omitempty"`
7+
RequestId string `json:"requestId,omitempty"`
8+
Data GetUserAuthResourceStructDataDto `json:"data"`
9+
}

0 commit comments

Comments
 (0)