MCPcopy Create free account
hub / github.com/OpenCSGs/csghub-server / CreateAppToken

Method CreateAppToken

user/handler/access_token.go:100–131  ·  view source on GitHub ↗

CreateAppToken godoc @Security ApiKey @Summary Create access token for an special application @Tags Access token @Accept json @Produce json @Param token_name path string true "token name" @Param app path string true "application" Enums(git,starship) @Param

(ctx *gin.Context)

Source from the content-addressed store, hash-verified

98// @Failure 500 {object} types.APIInternalServerError "Internal server error"
99// @Router /token/{app}/{token_name} [post]
100func (h *AccessTokenHandler) CreateAppToken(ctx *gin.Context) {
101 currentUser := httpbase.GetCurrentUser(ctx)
102 if currentUser == "" {
103 httpbase.UnauthorizedError(ctx, component.ErrUserNotFound)
104 return
105 }
106 var req types.CreateUserTokenRequest
107 if err := ctx.ShouldBindJSON(&req); err != nil {
108 slog.Error("Bad request format", "error", err)
109 httpbase.BadRequest(ctx, err.Error())
110 return
111 }
112 var err error
113 _, err = h.sc.CheckRequest(ctx, &req)
114 if err != nil {
115 slog.Error("failed to check sensitive request", slog.Any("error", err))
116 httpbase.BadRequest(ctx, fmt.Errorf("sensitive check failed: %w", err).Error())
117 return
118 }
119
120 req.Application = types.AccessTokenApp(ctx.Param("app"))
121 req.Username = currentUser
122 req.TokenName = ctx.Param("token_name")
123 token, err := h.c.Create(ctx, &req)
124 if err != nil {
125 slog.Error("Failed to create user access token", slog.String("user_name", req.Username), slog.Any("error", err))
126 httpbase.ServerError(ctx, err)
127 return
128 }
129
130 httpbase.OK(ctx, token)
131}
132
133// Deprecated: use DeleteAppToken instead
134// DeleteAccessToken godoc

Callers

nothing calls this directly

Calls 9

GetCurrentUserFunction · 0.92
UnauthorizedErrorFunction · 0.92
BadRequestFunction · 0.92
AccessTokenAppTypeAlias · 0.92
ServerErrorFunction · 0.92
OKFunction · 0.92
ErrorMethod · 0.80
CheckRequestMethod · 0.65
CreateMethod · 0.45

Tested by

no test coverage detected