Skip to content

Commit

Permalink
Merge pull request #47 from autodesk-platform-services/DAS-214
Browse files Browse the repository at this point in the history
[Das 214] - Fixes for Authentication SDK
  • Loading branch information
srivastavarahull authored Jun 28, 2024
2 parents 19319c3 + 2c9dfc0 commit 6e1c5ee
Show file tree
Hide file tree
Showing 18 changed files with 385 additions and 405 deletions.
160 changes: 61 additions & 99 deletions authentication/source/Http/TokenApi.gen.cs

Large diffs are not rendered by default.

82 changes: 38 additions & 44 deletions authentication/source/Http/UsersApi.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public interface IUsersApi
/// <exception cref="HttpRequestException">Thrown when fails to make API call</exception>
/// <param name="authorization">YOUR_3_LEGGED_ACCESS_TOKEN (optional)</param>
/// <returns>Task of ApiResponse&lt;UserInfo&gt;</returns>
System.Threading.Tasks.Task<ApiResponse<UserInfo>> GetUserinfoAsync (string authorization, bool throwOnError = true);

System.Threading.Tasks.Task<ApiResponse<UserInfo>> GetUserInfoAsync(string authorization, bool throwOnError = true);
}

/// <summary>
Expand All @@ -59,6 +59,9 @@ public partial class UsersApi : IUsersApi
{
ILogger logger;

// Manually added because UsersApi has a different base address.
public Uri BaseAddress { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="UsersApi"/> class
/// using SDKManager object
Expand All @@ -68,67 +71,68 @@ public partial class UsersApi : IUsersApi
public UsersApi(SDKManager.SDKManager sdkManager)
{
this.Service = sdkManager.ApsClient.Service;
this.BaseAddress = new Uri("https://api.userprofile.autodesk.com/");
this.logger = sdkManager.Logger;
}
private void SetQueryParameter(string name, object value, Dictionary<string, object> dictionary)
{
if(value is Enum)
if (value is Enum)
{
var type = value.GetType();
var memberInfos = type.GetMember(value.ToString());
var enumValueMemberInfo = memberInfos.FirstOrDefault(m => m.DeclaringType == type);
var valueAttributes = enumValueMemberInfo.GetCustomAttributes(typeof(EnumMemberAttribute), false);
if(valueAttributes.Length > 0)
if (valueAttributes.Length > 0)
{
dictionary.Add(name, ((EnumMemberAttribute)valueAttributes[0]).Value);
}
}
else if(value is int)
else if (value is int)
{
if((int)value > 0)
if ((int)value > 0)
{
dictionary.Add(name, value);
}
}
else
{
if(value != null)
if (value != null)
{
dictionary.Add(name, value);
}
}
}
private void SetHeader(string baseName, object value, HttpRequestMessage req)
{
if(value is DateTime)
if (value is DateTime)
{
if ((DateTime)value != DateTime.MinValue)
{
if((DateTime)value != DateTime.MinValue)
req.Headers.TryAddWithoutValidation(baseName, LocalMarshalling.ParameterToString(value)); // header parameter
}
}
else
{
if (value != null)
{
if (!string.Equals(baseName, "Content-Range"))
{
req.Headers.TryAddWithoutValidation(baseName, LocalMarshalling.ParameterToString(value)); // header parameter
}
}
else
{
if (value != null)
else
{
if(!string.Equals(baseName, "Content-Range"))
{
req.Headers.TryAddWithoutValidation(baseName, LocalMarshalling.ParameterToString(value)); // header parameter
}
else
{
req.Content.Headers.Add(baseName, LocalMarshalling.ParameterToString(value));
}
req.Content.Headers.Add(baseName, LocalMarshalling.ParameterToString(value));
}
}
}

}

/// <summary>
/// Gets or sets the ApsConfiguration object
/// </summary>
/// <value>An instance of the ForgeService</value>
public ForgeService Service {get; set;}
public ForgeService Service { get; set; }

/// <summary>
/// Get User Info
Expand All @@ -139,36 +143,24 @@ private void SetHeader(string baseName, object value, HttpRequestMessage req)
/// <exception cref="HttpRequestException">Thrown when fails to make API call</exception>
/// <param name="authorization">YOUR_3_LEGGED_ACCESS_TOKEN (optional)</param>
/// <returns>Task of ApiResponse&lt;UserInfo&gt;</returns>
public async System.Threading.Tasks.Task<ApiResponse<UserInfo>> GetUserinfoAsync (string authorization, bool throwOnError = true)

public async System.Threading.Tasks.Task<ApiResponse<UserInfo>> GetUserInfoAsync(string authorization, bool throwOnError = true)
{
logger.LogInformation("Entered into GetUserinfoAsync ");
logger.LogInformation("Entered into GetUserInfoAsync ");
using (var request = new HttpRequestMessage())
{
var queryParam = new Dictionary<string, object>();
// *** ss added manually
request.RequestUri = new Uri("https://api.userprofile.autodesk.com/userinfo");
// Marshalling.BuildRequestUri("/userinfo",
// routeParameters: new Dictionary<string, object> {
// },
// queryParameters: queryParam
// );
request.RequestUri = new Uri(BaseAddress, "/userinfo");

request.Headers.TryAddWithoutValidation("Accept", "application/json");
request.Headers.TryAddWithoutValidation("User-Agent", "APS SDK/AUTHENTICATION/C#/1.0.0-beta1");
if(!string.IsNullOrEmpty(authorization))
request.Headers.TryAddWithoutValidation("User-Agent", "APS SDK/AUTHENTICATION/C#/1.0.0");
if (!string.IsNullOrEmpty(authorization))
{
request.Headers.TryAddWithoutValidation("Authorization", $"Bearer {authorization}");
}



// SetHeader("Authorization", authorization, request);

// *** ss code end***

// tell the underlying pipeline what scope we'd like to use

request.Method = new HttpMethod("GET");

// make the HTTP request
Expand All @@ -178,17 +170,19 @@ public async System.Threading.Tasks.Task<ApiResponse<UserInfo>> GetUserinfoAsync
{
try
{
await response.EnsureSuccessStatusCodeAsync();
} catch (HttpRequestException ex) {
throw new AuthenticationApiException(ex.Message, response, ex);
await response.EnsureSuccessStatusCodeAsync();
}
catch (HttpRequestException ex)
{
throw new AuthenticationApiException(ex.Message, response, ex);
}
}
else if (!response.IsSuccessStatusCode)
{
logger.LogError($"response unsuccess with status code: {response.StatusCode}");
return new ApiResponse<UserInfo>(response, default(UserInfo));
}
logger.LogInformation($"Exited from GetUserinfoAsync with response statusCode: {response.StatusCode}");
logger.LogInformation($"Exited from GetUserInfoAsync with response statusCode: {response.StatusCode}");
return new ApiResponse<UserInfo>(response, await LocalMarshalling.DeserializeAsync<UserInfo>(response.Content));

} // using
Expand Down
File renamed without changes.
26 changes: 13 additions & 13 deletions authentication/source/Model/IntrospectToken.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,29 @@
namespace Autodesk.Authentication.Model
{
/// <summary>
/// IntrospectToken
/// Represents the payload returned for an introspect token request.
/// </summary>
[DataContract]
public partial class IntrospectToken
public partial class IntrospectToken
{
/// <summary>
/// Initializes a new instance of the <see cref="IntrospectToken" /> class.
/// </summary>
public IntrospectToken()
{
}

/// <summary>
///`true`: The token is active.
///
///`false`: The token is expired, invalid, or revoked.
///
///`false`: The token is expired, invalid, or revoked.
/// </summary>
/// <value>
///`true`: The token is active.
///
///`false`: The token is expired, invalid, or revoked.
///
///`false`: The token is expired, invalid, or revoked.
/// </value>
[DataMember(Name="active", EmitDefaultValue=false)]
[DataMember(Name = "active", EmitDefaultValue = false)]
public bool? Active { get; set; }

/// <summary>
Expand All @@ -64,7 +64,7 @@ public IntrospectToken()
/// <value>
///A URL-encoded, space separated list of scopes associated with the token.
/// </value>
[DataMember(Name="scope", EmitDefaultValue=false)]
[DataMember(Name = "scope", EmitDefaultValue = false)]
public string Scope { get; set; }

/// <summary>
Expand All @@ -73,7 +73,7 @@ public IntrospectToken()
/// <value>
///The Client ID of the application associated with the token.
/// </value>
[DataMember(Name="client_id", EmitDefaultValue=false)]
[DataMember(Name = "client_id", EmitDefaultValue = false)]
public string ClientId { get; set; }

/// <summary>
Expand All @@ -82,7 +82,7 @@ public IntrospectToken()
/// <value>
///The expiration time of the token, represented as a Unix timestamp.
/// </value>
[DataMember(Name="exp", EmitDefaultValue=false)]
[DataMember(Name = "exp", EmitDefaultValue = false)]
public int? Exp { get; set; }

/// <summary>
Expand All @@ -91,8 +91,8 @@ public IntrospectToken()
/// <value>
///The ID of the user who authorized the token.
/// </value>
[DataMember(Name="userid", EmitDefaultValue=false)]
public string Userid { get; set; }
[DataMember(Name = "userid", EmitDefaultValue = false)]
public string UserId { get; set; }

/// <summary>
/// Returns the string presentation of the object
Expand Down
7 changes: 5 additions & 2 deletions authentication/source/Model/Jwks.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
namespace Autodesk.Authentication.Model
{
/// <summary>
/// Jwks
/// Represents a successful response to a Get JWKS operation.
/// </summary>
[DataContract]
public partial class Jwks
Expand All @@ -46,8 +46,11 @@ public Jwks()
}

/// <summary>
///Gets or Sets Keys
///An array of objects where each object represents a JSON Web Key Set (JWKS).
/// </summary>
/// <value>
///An array of objects where each object represents a JSON Web Key Set (JWKS).
/// </value>
[DataMember(Name="keys", EmitDefaultValue=false)]
public List<JwksKey> Keys { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,25 @@
namespace Autodesk.Authentication.Model
{
/// <summary>
/// JwksKey
/// Represents a JSON Web Key Set (JWKS).
/// </summary>
[DataContract]
public partial class JwksKey
public partial class JwksKey
{
/// <summary>
/// Initializes a new instance of the <see cref="JwksKey" /> class.
/// </summary>
public JwksKey()
{
}

/// <summary>
///The ID of the key. Acts as a unique identifier for a specific key within the JWKS.
/// </summary>
/// <value>
///The ID of the key. Acts as a unique identifier for a specific key within the JWKS.
/// </value>
[DataMember(Name="kid", EmitDefaultValue=false)]
[DataMember(Name = "kid", EmitDefaultValue = false)]
public string Kid { get; set; }

/// <summary>
Expand All @@ -60,20 +60,20 @@ public JwksKey()
/// <value>
///The cryptographic algorithm family used with the key. Currently, always `RSA`.
/// </value>
[DataMember(Name="kty", EmitDefaultValue=false)]
[DataMember(Name = "kty", EmitDefaultValue = false)]
public string Kty { get; set; }

/// <summary>
///The intended use of the public key. Possible values:
///
///- `sig` - Verify the signature on data.
///
///- `sig` - Verify the signature on data.
/// </summary>
/// <value>
///The intended use of the public key. Possible values:
///
///- `sig` - Verify the signature on data.
///
///- `sig` - Verify the signature on data.
/// </value>
[DataMember(Name="use", EmitDefaultValue=false)]
[DataMember(Name = "use", EmitDefaultValue = false)]
public string Use { get; set; }

/// <summary>
Expand All @@ -82,7 +82,7 @@ public JwksKey()
/// <value>
///The RSA modulus value.
/// </value>
[DataMember(Name="n", EmitDefaultValue=false)]
[DataMember(Name = "n", EmitDefaultValue = false)]
public string N { get; set; }

/// <summary>
Expand All @@ -91,7 +91,7 @@ public JwksKey()
/// <value>
///The RSA exponent value.
/// </value>
[DataMember(Name="e", EmitDefaultValue=false)]
[DataMember(Name = "e", EmitDefaultValue = false)]
public string E { get; set; }

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions authentication/source/Model/OidcSpec.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
namespace Autodesk.Authentication.Model
{
/// <summary>
/// OIDC Specification
/// Represents a successful response to a Get OIDC Specification operation.
/// </summary>
[DataContract]
public partial class OidcSpec
Expand Down Expand Up @@ -79,7 +79,7 @@ public OidcSpec()
///The endpoint for querying information about the authenticated user.
/// </value>
[DataMember(Name="userinfo_endpoint", EmitDefaultValue=false)]
public string UserinfoEndpoint { get; set; }
public string UserInfoEndpoint { get; set; }

/// <summary>
///The endpoint for retrieving public keys used by APS, in the JWKS format.
Expand Down
Loading

0 comments on commit 6e1c5ee

Please sign in to comment.