Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C#][2.0] add bearer auth support to C# 2.0 client #5978

Merged
merged 1 commit into from
Apr 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/csharp-dotnet2-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g csharp-dotnet2 -o samples/client/petstore/csharp-dotnet2/OpenAPIClientTest/Lib/OpenAPIClient --additional-properties hideGenerationTimestamp=true $@"
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g csharp-dotnet2 -t modules/openapi-generator/src/main/resources/csharp-dotnet2 -o samples/client/petstore/csharp-dotnet2/OpenAPIClientTest/Lib/OpenAPIClient --additional-properties hideGenerationTimestamp=true $@"

java $JAVA_OPTS -jar $executable $ags
2 changes: 1 addition & 1 deletion bin/windows/csharp-dotnet2-petstore.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ If Not Exist %executable% (
)

REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
set ags=generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g csharp-dotnet2 -o samples/client/petstore/csharp-dotnet2/OpenApiClientTest/Lib/OpenApiClient --additional-properties hideGenerationTimestamp=true
set ags=generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g csharp-dotnet2 -t modules/openapi-generator/src/main/resources/csharp-dotnet2 -o samples/client/petstore/csharp-dotnet2/OpenApiClientTest/Lib/OpenApiClient --additional-properties hideGenerationTimestamp=true

java %JAVA_OPTS% -jar %executable% %ags%
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,25 @@ namespace {{clientPackage}}
{
{{#authMethods}}
case "{{name}}":
{{#isApiKey}}{{#isKeyInHeader}}headerParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");{{/isKeyInHeader}}{{#isKeyInQuery}}queryParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}headerParams["Authorization"] = "Basic " + Base64Encode(Configuration.Username + ":" + Configuration.Password);{{/isBasic}}
{{#isOAuth}}//TODO support oauth{{/isOAuth}}
{{#isApiKey}}
{{#isKeyInHeader}}
headerParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");
{{/isKeyInHeader}}
{{#isKeyInQuery}}
queryParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");
{{/isKeyInQuery}}
{{/isApiKey}}
{{#isBasic}}
{{#isBasicBasic}}
headerParams["Authorization"] = "Basic " + Base64Encode(Configuration.Username + ":" + Configuration.Password);
{{/isBasicBasic}}
{{#isBasicBearer}}
headerParams["Authorization"] = "Bearer " + Configuration.AccessToken;
{{/isBasicBearer}}
{{/isBasic}}
{{#isOAuth}}
headerParams["Authorization"] = "Bearer " + Configuration.AccessToken;
{{/isOAuth}}
break;
{{/authMethods}}
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ namespace {{clientPackage}}
/// <value>The password.</value>
public static String Password { get; set; }

/// <summary>
/// Gets or sets the access token (Bearer/OAuth authentication).
/// </summary>
/// <value>The access token.</value>
public static String AccessToken { get; set; }

/// <summary>
/// Gets or sets the API key based on the authentication name.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,31 @@ namespace Example
{
public void main()
{
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}{{#hasAuthMethods}}{{#authMethods}}{{#isBasic}}
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}
{{#hasAuthMethods}}
{{#authMethods}}
{{#isBasic}}
{{#isBasicBasic}}
// Configure HTTP basic authorization: {{{name}}}
Configuration.Default.Username = "YOUR_USERNAME";
Configuration.Default.Password = "YOUR_PASSWORD";{{/isBasic}}{{#isApiKey}}
Configuration.Default.Password = "YOUR_PASSWORD";
{{/isBasicBasic}}
{{#isBasicBearer}}
// Configure Bearer access token for authorization: {{{name}}}
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";
{{/isBasicBearer}}
{{/isBasic}}
{{#isApiKey}}
// Configure API key authorization: {{{name}}}
Configuration.Default.ApiKey.Add("{{{keyParamName}}}", "YOUR_API_KEY");
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// Configuration.Default.ApiKeyPrefix.Add("{{{keyParamName}}}", "Bearer");{{/isApiKey}}{{#isOAuth}}
// Configuration.Default.ApiKeyPrefix.Add("{{{keyParamName}}}", "Bearer");
{{/isApiKey}}
{{#isOAuth}}
// Configure OAuth2 access token for authorization: {{{name}}}
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";{{/isOAuth}}{{/authMethods}}
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";
{{/isOAuth}}
{{/authMethods}}
{{/hasAuthMethods}}

var apiInstance = new {{classname}}();
Expand Down Expand Up @@ -123,21 +138,29 @@ No model defined in this package
All endpoints do not require authorization.
{{/authMethods}}
{{#authMethods}}
{{#last}}
{{#-last}}
Authentication schemes defined for the API:
{{/last}}
{{/-last}}
{{/authMethods}}
{{#authMethods}}
<a name="{{name}}"></a>
### {{name}}

{{#isApiKey}}- **Type**: API key
{{#isApiKey}}
- **Type**: API key
- **API key parameter name**: {{keyParamName}}
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
{{/isApiKey}}
{{#isBasic}}- **Type**: HTTP basic authentication
{{#isBasic}}
{{#isBasicBasic}}
- **Type**: HTTP basic authentication
{{/isBasicBasic}}
{{#isBasicBearer}}
- **Type**: HTTP bearer authentication
{{/isBasicBearer}}
{{/isBasic}}
{{#isOAuth}}- **Type**: OAuth
{{#isOAuth}}
- **Type**: OAuth
- **Flow**: {{flow}}
- **Authorization URL**: {{authorizationUrl}}
- **Scopes**: {{^scopes}}N/A{{/scopes}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,32 @@ namespace Example
{
public void main()
{
{{#hasAuthMethods}}{{#authMethods}}{{#isBasic}}
{{#hasAuthMethods}}
{{#authMethods}}
{{#isBasic}}
{{#isBasicBasic}}
// Configure HTTP basic authorization: {{{name}}}
Configuration.Default.Username = "YOUR_USERNAME";
Configuration.Default.Password = "YOUR_PASSWORD";{{/isBasic}}{{#isApiKey}}
Configuration.Default.Password = "YOUR_PASSWORD";
{{/isBasicBasic}}
{{#isBasicBearer}}
// Configure Bearer access token: {{{name}}}
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";
{{/isBasicBearer}}
{{/isBasic}}
{{#isApiKey}}
// Configure API key authorization: {{{name}}}
Configuration.Default.ApiKey.Add("{{{keyParamName}}}", "YOUR_API_KEY");
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// Configuration.Default.ApiKeyPrefix.Add("{{{keyParamName}}}", "Bearer");{{/isApiKey}}{{#isOAuth}}
// Configuration.Default.ApiKeyPrefix.Add("{{{keyParamName}}}", "Bearer");
{{/isApiKey}}
{{#isOAuth}}
// Configure OAuth2 access token for authorization: {{{name}}}
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";{{/isOAuth}}{{/authMethods}}
{{/hasAuthMethods}}
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";
{{/isOAuth}}
{{/authMethods}}

{{/hasAuthMethods}}
var apiInstance = new {{classname}}();
{{#allParams}}
{{#isPrimitiveType}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Class | Method | HTTP request | Description
<a name="documentation-for-authorization"></a>
## Documentation for Authorization

Authentication schemes defined for the API:
<a name="api_key"></a>
### api_key

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ namespace Example
{
public void main()
{

// Configure OAuth2 access token for authorization: petstore_auth
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";

Expand Down Expand Up @@ -96,7 +95,6 @@ namespace Example
{
public void main()
{

// Configure OAuth2 access token for authorization: petstore_auth
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";

Expand Down Expand Up @@ -162,7 +160,6 @@ namespace Example
{
public void main()
{

// Configure OAuth2 access token for authorization: petstore_auth
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";

Expand Down Expand Up @@ -227,7 +224,6 @@ namespace Example
{
public void main()
{

// Configure OAuth2 access token for authorization: petstore_auth
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";

Expand Down Expand Up @@ -292,7 +288,6 @@ namespace Example
{
public void main()
{

// Configure API key authorization: api_key
Configuration.Default.ApiKey.Add("api_key", "YOUR_API_KEY");
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
Expand Down Expand Up @@ -357,7 +352,6 @@ namespace Example
{
public void main()
{

// Configure OAuth2 access token for authorization: petstore_auth
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";

Expand Down Expand Up @@ -419,7 +413,6 @@ namespace Example
{
public void main()
{

// Configure OAuth2 access token for authorization: petstore_auth
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";

Expand Down Expand Up @@ -485,7 +478,6 @@ namespace Example
{
public void main()
{

// Configure OAuth2 access token for authorization: petstore_auth
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ namespace Example
{
public void main()
{

var apiInstance = new StoreApi();
var orderId = orderId_example; // string | ID of the order that needs to be deleted

Expand Down Expand Up @@ -93,7 +92,6 @@ namespace Example
{
public void main()
{

// Configure API key authorization: api_key
Configuration.Default.ApiKey.Add("api_key", "YOUR_API_KEY");
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
Expand Down Expand Up @@ -156,7 +154,6 @@ namespace Example
{
public void main()
{

var apiInstance = new StoreApi();
var orderId = 789; // long? | ID of pet that needs to be fetched

Expand Down Expand Up @@ -216,7 +213,6 @@ namespace Example
{
public void main()
{

var apiInstance = new StoreApi();
var body = new Order(); // Order | order placed for purchasing the pet

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ namespace Example
{
public void main()
{

var apiInstance = new UserApi();
var body = new User(); // User | Created user object

Expand Down Expand Up @@ -95,7 +94,6 @@ namespace Example
{
public void main()
{

var apiInstance = new UserApi();
var body = new List<User>(); // List<User> | List of user object

Expand Down Expand Up @@ -154,7 +152,6 @@ namespace Example
{
public void main()
{

var apiInstance = new UserApi();
var body = new List<User>(); // List<User> | List of user object

Expand Down Expand Up @@ -215,7 +212,6 @@ namespace Example
{
public void main()
{

var apiInstance = new UserApi();
var username = username_example; // string | The name that needs to be deleted

Expand Down Expand Up @@ -274,7 +270,6 @@ namespace Example
{
public void main()
{

var apiInstance = new UserApi();
var username = username_example; // string | The name that needs to be fetched. Use user1 for testing.

Expand Down Expand Up @@ -334,7 +329,6 @@ namespace Example
{
public void main()
{

var apiInstance = new UserApi();
var username = username_example; // string | The user name for login
var password = password_example; // string | The password for login in clear text
Expand Down Expand Up @@ -396,7 +390,6 @@ namespace Example
{
public void main()
{

var apiInstance = new UserApi();

try
Expand Down Expand Up @@ -453,7 +446,6 @@ namespace Example
{
public void main()
{

var apiInstance = new UserApi();
var username = username_example; // string | name that need to be deleted
var body = new User(); // User | Updated user object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,9 @@ public void UpdateParamsForAuth(Dictionary<String, String> queryParams, Dictiona
{
case "api_key":
headerParams["api_key"] = GetApiKeyWithPrefix("api_key");

break;
case "petstore_auth":

//TODO support oauth
headerParams["Authorization"] = "Bearer " + Configuration.AccessToken;
break;
default:
//TODO show warning about security definition not found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public class Configuration
/// <value>The password.</value>
public static String Password { get; set; }

/// <summary>
/// Gets or sets the access token (Bearer/OAuth authentication).
/// </summary>
/// <value>The access token.</value>
public static String AccessToken { get; set; }

/// <summary>
/// Gets or sets the API key based on the authentication name.
/// </summary>
Expand Down