add oauth support to csharp

This commit is contained in:
wing328
2015-11-05 16:49:38 +08:00
parent a3b90c516d
commit 5a8d2c834f
6 changed files with 14 additions and 5 deletions

View File

@@ -319,8 +319,7 @@ namespace {{packageName}}.Client
{
{{#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}}headerParams["Authorization"] = "Basic " + Base64Encode(Configuration.Username + ":" + Configuration.Password);{{/isBasic}}{{#isOAuth}}headerParams["Authorization"] = "Bearer " + Configuration.AccessToken;{{/isOAuth}}
break;
{{/authMethods}}
default:

View File

@@ -37,6 +37,12 @@ namespace {{packageName}}.Client
/// <value>The password.</value>
public static String Password { get; set; }
/// <summary>
/// Gets or sets the access token for OAuth2 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>

View File

@@ -320,12 +320,10 @@ namespace IO.Swagger.Client
case "api_key":
headerParams["api_key"] = GetApiKeyWithPrefix("api_key");
break;
case "petstore_auth":
//TODO support oauth
headerParams["Authorization"] = "Bearer " + Configuration.AccessToken;
break;
default:

View File

@@ -37,6 +37,12 @@ namespace IO.Swagger.Client
/// <value>The password.</value>
public static String Password { get; set; }
/// <summary>
/// Gets or sets the access token for OAuth2 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>