| OLD | NEW |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. | 1 // Copyright 2017 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package serviceaccounts | 5 package serviceaccounts |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "golang.org/x/net/context" | 8 "golang.org/x/net/context" |
| 9 "google.golang.org/grpc" | 9 "google.golang.org/grpc" |
| 10 "google.golang.org/grpc/codes" | 10 "google.golang.org/grpc/codes" |
| 11 | 11 |
| 12 "github.com/luci/luci-go/server/auth/signing" |
| 13 |
| 14 "github.com/luci/luci-go/tokenserver/api" |
| 12 "github.com/luci/luci-go/tokenserver/api/admin/v1" | 15 "github.com/luci/luci-go/tokenserver/api/admin/v1" |
| 13 ) | 16 ) |
| 14 | 17 |
| 15 // InspectOAuthTokenGrantRPC implements Admin.InspectOAuthTokenGrant method. | 18 // InspectOAuthTokenGrantRPC implements admin.InspectOAuthTokenGrant method. |
| 16 type InspectOAuthTokenGrantRPC struct { | 19 type InspectOAuthTokenGrantRPC struct { |
| 20 // Signer is mocked in tests. |
| 21 // |
| 22 // In prod it is gaesigner.Signer. |
| 23 Signer signing.Signer |
| 17 } | 24 } |
| 18 | 25 |
| 19 // InspectOAuthTokenGrant decodes the given OAuth token grant. | 26 // InspectOAuthTokenGrant decodes the given OAuth token grant. |
| 20 func (r *ImportServiceAccountsConfigsRPC) InspectOAuthTokenGrant(c context.Conte
xt, req *admin.InspectOAuthTokenGrantRequest) (*admin.InspectOAuthTokenGrantResp
onse, error) { | 27 func (r *InspectOAuthTokenGrantRPC) InspectOAuthTokenGrant(c context.Context, re
q *admin.InspectOAuthTokenGrantRequest) (*admin.InspectOAuthTokenGrantResponse,
error) { |
| 21 » return nil, grpc.Errorf(codes.Unavailable, "not implemented") | 28 » inspection, err := InspectGrant(c, r.Signer, req.Token) |
| 29 » if err != nil { |
| 30 » » return nil, grpc.Errorf(codes.Internal, err.Error()) |
| 31 » } |
| 32 » resp := &admin.InspectOAuthTokenGrantResponse{ |
| 33 » » Valid: inspection.Signed && inspection.NonExpired, |
| 34 » » Signed: inspection.Signed, |
| 35 » » NonExpired: inspection.NonExpired, |
| 36 » » InvalidityReason: inspection.InvalidityReason, |
| 37 » } |
| 38 » if env, _ := inspection.Envelope.(*tokenserver.OAuthTokenGrantEnvelope);
env != nil { |
| 39 » » resp.SigningKeyId = env.KeyId |
| 40 » } |
| 41 » resp.TokenBody, _ = inspection.Body.(*tokenserver.OAuthTokenGrantBody) |
| 42 » return resp, nil |
| 22 } | 43 } |
| OLD | NEW |