Skip to content

Commit 36c2db8

Browse files
authored
multiple oauth tokens (#23264)
1 parent 2cad996 commit 36c2db8

119 files changed

Lines changed: 987 additions & 112 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-generator/src/main/resources/csharp/libraries/generichost/DependencyInjectionTests.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ namespace {{packageName}}.Test.{{apiPackage}}
7676

7777
{{/httpSignatureMethods}}
7878
{{#oauthMethods}}
79-
OAuthToken oauthToken = new{{^net70OrLater}} OAuthToken{{/net70OrLater}}("token", timeout: TimeSpan.FromSeconds(1));
80-
options.AddTokens(oauthToken);
79+
OAuthToken oauthToken{{-index}} = new{{^net70OrLater}} OAuthToken{{/net70OrLater}}("token", timeout: TimeSpan.FromSeconds(1));
80+
options.AddTokens(oauthToken{{-index}});
8181

8282
{{/oauthMethods}}
8383
{{/lambda.trimTrailingWithNewLine}}

modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ paths:
7373
- petstore_auth:
7474
- 'write:pets'
7575
- 'read:pets'
76+
- petstore_auth2:
77+
- 'write:pets'
78+
- 'read:pets'
7679
requestBody:
7780
$ref: '#/components/requestBodies/Pet'
7881
put:
@@ -1430,6 +1433,14 @@ components:
14301433
scopes:
14311434
'write:pets': modify pets in your account
14321435
'read:pets': read your pets
1436+
petstore_auth2:
1437+
type: oauth2
1438+
flows:
1439+
implicit:
1440+
authorizationUrl: 'http://petstore.swagger.io/api/oauth/dialog'
1441+
scopes:
1442+
'write:pets': modify pets in your account
1443+
'read:pets': read your pets
14331444
api_key:
14341445
type: apiKey
14351446
name: api-key

samples/client/petstore/csharp/generichost/net10/FormModels/api/openapi.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ paths:
9090
- petstore_auth:
9191
- write:pets
9292
- read:pets
93+
- petstore_auth2:
94+
- write:pets
95+
- read:pets
9396
summary: Add a new pet to the store
9497
tags:
9598
- pet
@@ -3116,6 +3119,14 @@ components:
31163119
write:pets: modify pets in your account
31173120
read:pets: read your pets
31183121
type: oauth2
3122+
petstore_auth2:
3123+
flows:
3124+
implicit:
3125+
authorizationUrl: http://petstore.swagger.io/api/oauth/dialog
3126+
scopes:
3127+
write:pets: modify pets in your account
3128+
read:pets: read your pets
3129+
type: oauth2
31193130
api_key:
31203131
in: header
31213132
name: api-key

samples/client/petstore/csharp/generichost/net10/FormModels/docs/apis/PetApi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void (empty response body)
3434

3535
### Authorization
3636

37-
[petstore_auth](../README.md#petstore_auth), [http_signature_test](../README.md#http_signature_test)
37+
[petstore_auth](../README.md#petstore_auth), [petstore_auth2](../README.md#petstore_auth2), [http_signature_test](../README.md#http_signature_test)
3838

3939
### HTTP request headers
4040

samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools.Test/Api/ApiTestsBase.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaul
7676
string oauthTokenValue1 = context.Configuration["<token>"] ?? throw new Exception("Token not found.");
7777
OAuthToken oauthToken1 = new(oauthTokenValue1, timeout: TimeSpan.FromSeconds(1));
7878
options.AddTokens(oauthToken1);
79+
string oauthTokenValue2 = context.Configuration["<token>"] ?? throw new Exception("Token not found.");
80+
OAuthToken oauthToken2 = new(oauthTokenValue2, timeout: TimeSpan.FromSeconds(1));
81+
options.AddTokens(oauthToken2);
7982
});
8083
}
8184
}

samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools.Test/Api/DependencyInjectionTests.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public class DependencyInjectionTest
4545

4646
OAuthToken oauthToken1 = new("token", timeout: TimeSpan.FromSeconds(1));
4747
options.AddTokens(oauthToken1);
48+
49+
OAuthToken oauthToken2 = new("token", timeout: TimeSpan.FromSeconds(1));
50+
options.AddTokens(oauthToken2);
4851
})
4952
.Build();
5053

@@ -67,8 +70,11 @@ public class DependencyInjectionTest
6770
HttpSignatureToken httpSignatureToken1 = new(config1, timeout: TimeSpan.FromSeconds(1));
6871
options.AddTokens(httpSignatureToken1);
6972

70-
OAuthToken oauthToken = new("token", timeout: TimeSpan.FromSeconds(1));
71-
options.AddTokens(oauthToken);
73+
OAuthToken oauthToken1 = new("token", timeout: TimeSpan.FromSeconds(1));
74+
options.AddTokens(oauthToken1);
75+
76+
OAuthToken oauthToken2 = new("token", timeout: TimeSpan.FromSeconds(1));
77+
options.AddTokens(oauthToken2);
7278
options.AddApiHttpClients(client => client.BaseAddress = new Uri(ClientUtils.BASE_ADDRESS));
7379
})
7480
.Build();
@@ -96,6 +102,9 @@ public class DependencyInjectionTest
96102

97103
OAuthToken oauthToken1 = new("token", timeout: TimeSpan.FromSeconds(1));
98104
options.AddTokens(oauthToken1);
105+
106+
OAuthToken oauthToken2 = new("token", timeout: TimeSpan.FromSeconds(1));
107+
options.AddTokens(oauthToken2);
99108
});
100109
})
101110
.Build();
@@ -123,6 +132,9 @@ public class DependencyInjectionTest
123132

124133
OAuthToken oauthToken1 = new("token", timeout: TimeSpan.FromSeconds(1));
125134
options.AddTokens(oauthToken1);
135+
136+
OAuthToken oauthToken2 = new("token", timeout: TimeSpan.FromSeconds(1));
137+
options.AddTokens(oauthToken2);
126138
options.AddApiHttpClients(client => client.BaseAddress = new Uri(ClientUtils.BASE_ADDRESS));
127139
});
128140
})

samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Api/PetApi.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -847,14 +847,20 @@ public async Task<IAddPetApiResponse> AddPetAsync(Pet pet, System.Threading.Canc
847847

848848
oauthTokenLocalVar1.UseInHeader(httpRequestMessageLocalVar, "");
849849

850-
HttpSignatureToken httpSignatureTokenLocalVar2 = (HttpSignatureToken) await HttpSignatureTokenProvider.GetAsync(cancellation: cancellationToken).ConfigureAwait(false);
850+
OAuthToken oauthTokenLocalVar2 = (OAuthToken) await OauthTokenProvider.GetAsync(cancellation: cancellationToken).ConfigureAwait(false);
851851

852-
tokenBaseLocalVars.Add(httpSignatureTokenLocalVar2);
852+
tokenBaseLocalVars.Add(oauthTokenLocalVar2);
853+
854+
oauthTokenLocalVar2.UseInHeader(httpRequestMessageLocalVar, "");
855+
856+
HttpSignatureToken httpSignatureTokenLocalVar3 = (HttpSignatureToken) await HttpSignatureTokenProvider.GetAsync(cancellation: cancellationToken).ConfigureAwait(false);
857+
858+
tokenBaseLocalVars.Add(httpSignatureTokenLocalVar3);
853859

854860
if (httpRequestMessageLocalVar.Content != null) {
855861
string requestBodyLocalVar = await httpRequestMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
856862

857-
httpSignatureTokenLocalVar2.UseInHeader(httpRequestMessageLocalVar, requestBodyLocalVar, cancellationToken);
863+
httpSignatureTokenLocalVar3.UseInHeader(httpRequestMessageLocalVar, requestBodyLocalVar, cancellationToken);
858864
}
859865

860866
string[] contentTypes = new string[] {

samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/api/openapi.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ paths:
9090
- petstore_auth:
9191
- write:pets
9292
- read:pets
93+
- petstore_auth2:
94+
- write:pets
95+
- read:pets
9396
summary: Add a new pet to the store
9497
tags:
9598
- pet
@@ -3136,6 +3139,14 @@ components:
31363139
write:pets: modify pets in your account
31373140
read:pets: read your pets
31383141
type: oauth2
3142+
petstore_auth2:
3143+
flows:
3144+
implicit:
3145+
authorizationUrl: http://petstore.swagger.io/api/oauth/dialog
3146+
scopes:
3147+
write:pets: modify pets in your account
3148+
read:pets: read your pets
3149+
type: oauth2
31393150
api_key:
31403151
in: header
31413152
name: api-key

samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/docs/apis/PetApi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void (empty response body)
3434

3535
### Authorization
3636

37-
[petstore_auth](../README.md#petstore_auth), [http_signature_test](../README.md#http_signature_test)
37+
[petstore_auth](../README.md#petstore_auth), [petstore_auth2](../README.md#petstore_auth2), [http_signature_test](../README.md#http_signature_test)
3838

3939
### HTTP request headers
4040

samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/ApiTestsBase.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaul
7676
string oauthTokenValue1 = context.Configuration["<token>"] ?? throw new Exception("Token not found.");
7777
OAuthToken oauthToken1 = new(oauthTokenValue1, timeout: TimeSpan.FromSeconds(1));
7878
options.AddTokens(oauthToken1);
79+
string oauthTokenValue2 = context.Configuration["<token>"] ?? throw new Exception("Token not found.");
80+
OAuthToken oauthToken2 = new(oauthTokenValue2, timeout: TimeSpan.FromSeconds(1));
81+
options.AddTokens(oauthToken2);
7982
});
8083
}
8184
}

0 commit comments

Comments
 (0)