(ctx context.Context, req *adminv1.ListUserAuthTokensRequest)
| 175 | } |
| 176 | |
| 177 | func (s *Server) ListUserAuthTokens(ctx context.Context, req *adminv1.ListUserAuthTokensRequest) (*adminv1.ListUserAuthTokensResponse, error) { |
| 178 | observability.AddRequestAttributes(ctx, |
| 179 | attribute.String("args.user_id", req.UserId), |
| 180 | ) |
| 181 | |
| 182 | claims := auth.GetClaims(ctx) |
| 183 | forceAccess := claims.Superuser(ctx) && req.SuperuserForceAccess |
| 184 | |
| 185 | userID := req.UserId |
| 186 | if userID == "current" { // Special alias for the current user |
| 187 | if claims.OwnerType() != auth.OwnerTypeUser { |
| 188 | return nil, status.Error(codes.Unauthenticated, "not authenticated as a user") |
| 189 | } |
| 190 | userID = claims.OwnerID() |
| 191 | } |
| 192 | if userID != claims.OwnerID() && !forceAccess { |
| 193 | return nil, status.Error(codes.PermissionDenied, "not authorized to list auth tokens for other users") |
| 194 | } |
| 195 | |
| 196 | pageSize := validPageSize(req.PageSize) |
| 197 | pageToken, err := unmarshalPageToken(req.PageToken) |
| 198 | if err != nil { |
| 199 | return nil, err |
| 200 | } |
| 201 | |
| 202 | authTokens, err := s.admin.DB.FindUserAuthTokens(ctx, userID, pageToken.Val, pageSize, req.Refresh) |
| 203 | if err != nil { |
| 204 | return nil, err |
| 205 | } |
| 206 | |
| 207 | nextToken := "" |
| 208 | if len(authTokens) >= pageSize { |
| 209 | nextToken = marshalPageToken(authTokens[len(authTokens)-1].ID) |
| 210 | } |
| 211 | |
| 212 | dtos := make([]*adminv1.UserAuthToken, len(authTokens)) |
| 213 | for i, t := range authTokens { |
| 214 | var authClientID, authClientDisplayName, representingUserID string |
| 215 | var expiresOn *timestamppb.Timestamp |
| 216 | if t.AuthClientID != nil { |
| 217 | authClientID = *t.AuthClientID |
| 218 | } |
| 219 | if t.AuthClientDisplayName != nil { |
| 220 | authClientDisplayName = *t.AuthClientDisplayName |
| 221 | } |
| 222 | if t.RepresentingUserID != nil { |
| 223 | representingUserID = *t.RepresentingUserID |
| 224 | } |
| 225 | if t.ExpiresOn != nil { |
| 226 | expiresOn = timestamppb.New(*t.ExpiresOn) |
| 227 | } |
| 228 | |
| 229 | id, err := uuid.Parse(t.ID) |
| 230 | if err != nil { |
| 231 | return nil, status.Errorf(codes.Internal, "invalid token ID %q: %v", t.ID, err) |
| 232 | } |
| 233 | |
| 234 | prefix := authtoken.FromID(authtoken.TypeUser, id).Prefix() |
nothing calls this directly
no test coverage detected