go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/tokenserver/appengine/impl/delegation/rpc_inspect_delegation_token.go (about) 1 // Copyright 2016 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package delegation 16 17 import ( 18 "context" 19 20 "google.golang.org/grpc/codes" 21 "google.golang.org/grpc/status" 22 23 "go.chromium.org/luci/server/auth/delegation/messages" 24 "go.chromium.org/luci/server/auth/signing" 25 26 admin "go.chromium.org/luci/tokenserver/api/admin/v1" 27 ) 28 29 // InspectDelegationTokenRPC implements Admin.InspectDelegationToken RPC method. 30 // 31 // It assumes authorization has happened already. 32 type InspectDelegationTokenRPC struct { 33 // Signer is mocked in tests. 34 // 35 // In prod it is the default server signer that uses server's service account. 36 Signer signing.Signer 37 } 38 39 func (r *InspectDelegationTokenRPC) InspectDelegationToken(c context.Context, req *admin.InspectDelegationTokenRequest) (*admin.InspectDelegationTokenResponse, error) { 40 inspection, err := InspectToken(c, r.Signer, req.Token) 41 if err != nil { 42 return nil, status.Errorf(codes.Internal, "%s", err) 43 } 44 resp := &admin.InspectDelegationTokenResponse{ 45 Valid: inspection.Signed && inspection.NonExpired, 46 Signed: inspection.Signed, 47 NonExpired: inspection.NonExpired, 48 InvalidityReason: inspection.InvalidityReason, 49 } 50 resp.Envelope, _ = inspection.Envelope.(*messages.DelegationToken) 51 resp.Subtoken, _ = inspection.Body.(*messages.Subtoken) 52 return resp, nil 53 }