« blib/lib/Google/Auth/ExternalAccountCredentials/Pluggable.pm
↑ Summary
blib/lib/Google/Auth/IDTokens/Verifier.pm »
| 1 | # Copyright 2022 Google LLC and contributors | ||
| 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 | use Moo; | ||
| 16 | |||
| 17 | has selector => ( | ||
| 18 | is => 'ro', | ||
| 19 | required => 0, | ||
| 20 | ); | ||
| 21 | |||
| 22 | has token => ( | ||
| 23 | is => 'ro', | ||
| 24 | required => 0, | ||
| 25 | ); | ||
| 26 | |||
| 27 | sub apply { | ||
| 28 | my ($self, $req_or_headers) = @_; | ||
| 29 | |||
| 30 | if (ref $req_or_headers eq 'HASH') { | ||
| 31 | $req_or_headers->{'x-goog-iam-authority-selector'} = $self->selector | ||
| 32 | if defined $self->selector; | ||
| 33 | $req_or_headers->{'x-goog-iam-authorization-token'} = $self->token | ||
| 34 | if defined $self->token; | ||
| 35 | } elsif (eval { $req_or_headers->isa('HTTP::Request') }) { | ||
| 36 | $req_or_headers->header('x-goog-iam-authority-selector' => $self->selector) | ||
| 37 | if defined $self->selector; | ||
| 38 | $req_or_headers->header('x-goog-iam-authorization-token' => $self->token) | ||
| 39 | if defined $self->token; | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | 1; |