Skip to content

Commit

Permalink
Merge pull request #428 from apigee/issue422
Browse files Browse the repository at this point in the history
feat: include email in the id token #422
  • Loading branch information
ssvaidyanathan authored Mar 6, 2024
2 parents 0b4747f + 5edafbf commit ce20f51
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 12 deletions.
22 changes: 15 additions & 7 deletions internal/bundlegen/generateapiv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,39 @@ func TestGenerateAPIProxyDefFromOASv2(specName string, t *testing.T) {
skipPolicy := false
name := "test"
addCORS := true
integrationEndpoint := false
basePath := ""
oasGoogleAcessTokenScopeLiteral := ""
targetURL := "http://api.example.com"
oasGoogleIDTokenAudLiteral := ""
oasGoogleIDTokenAudRef := ""
targetURLRef := ""
targetServerName := ""
version := GetModelVersion()
if version != "" {
re := regexp.MustCompile(`3\.1\.[0-9]`)
if re.MatchString(version) {
skipPolicy = true
}
}

targetOptions := TargetOptions{
IntegrationBackend: IntegrationBackendOptions{},
HttpBackend: HttpBackendOptions{
OasGoogleAcessTokenScopeLiteral: oasGoogleAcessTokenScopeLiteral,
OasGoogleIDTokenAudLiteral: oasGoogleIDTokenAudLiteral,
OasGoogleIDTokenAudRef: oasGoogleIDTokenAudRef,
OasTargetURLRef: targetURLRef,
TargetURL: targetURL,
TargetServerName: targetServerName,
},
}

if err := GenerateAPIProxyDefFromOASv2(name,
basePath,
specName,
skipPolicy,
addCORS,
integrationEndpoint,
oasGoogleAcessTokenScopeLiteral,
oasGoogleIDTokenAudLiteral,
oasGoogleIDTokenAudRef,
targetURLRef,
targetURL); err != nil {
targetOptions); err != nil {
t.Fatalf("%v", err)
}
}
6 changes: 4 additions & 2 deletions internal/bundlegen/targets/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ type googleAccessTokenDef struct {
}

type googleIdTokenDef struct {
XMLName xml.Name `xml:"GoogleIDToken"`
Audience *audienceDef `xml:"Audience"`
XMLName xml.Name `xml:"GoogleIDToken"`
IncludeEmail string `xml:"IncludeEmail"`
Audience *audienceDef `xml:"Audience"`
}

type audienceDef struct {
Expand Down Expand Up @@ -143,6 +144,7 @@ func NewTargetEndpoint(name string, endpoint string, targetServerBasePath string
targetEndpoint.HTTPTargetConnection.Authentication = new(authenticationDef)
targetEndpoint.HTTPTargetConnection.Authentication.GoogleIDToken = new(googleIdTokenDef)

targetEndpoint.HTTPTargetConnection.Authentication.GoogleIDToken.IncludeEmail = "true"
targetEndpoint.HTTPTargetConnection.Authentication.GoogleIDToken.Audience = new(audienceDef)

if oasGoogleIdTokenAudLiteral != "" {
Expand Down
File renamed without changes.
25 changes: 25 additions & 0 deletions test/minspec-oauth.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

openapi: 3.0.2
servers:
- url: https://my.example.com/api
components:
securitySchemes:
proxy_auth:
type: oauth2
flows:
clientCredentials:
tokenUrl: 'https://api.example.com/oauth/token'
refreshUrl: 'https://api.example.com/oauth/refresh'
23 changes: 23 additions & 0 deletions test/minspec-quota.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

openapi: 3.0.2
servers:
- url: https://my.example.com/api
x-google-quota:
- name: test1
interval-literal: 1
timeunit-literal: minute
allow-literal: 1
identifier-literal: request.headers.url
3 changes: 0 additions & 3 deletions test/minspec2.yaml → test/minspec-ratelimit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
# limitations under the License.

openapi: 3.0.2
info:
version: 0.0.1
title: Minimal Spec
servers:
- url: https://my.example.com/api
x-google-ratelimit:
Expand Down

0 comments on commit ce20f51

Please sign in to comment.