Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
using System.IO;
using eBay.ApiClient.Auth.OAuth2.Model;
using YamlDotNet.RepresentationModel;
using log4net;
using System.Collections.Concurrent;
using Microsoft.Extensions.Logging;

namespace eBay.ApiClient.Auth.OAuth2
{
public static class CredentialUtil {

private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
static readonly ConcurrentDictionary<String, Credentials> envCredentials = new ConcurrentDictionary<String, Credentials>();

public class Credentials {
Expand Down Expand Up @@ -56,17 +55,17 @@ public String Get(CredentialType credentialType)
/*
* Loading StreamReader
*/
public static void Load(String yamlFile)
public static void Load(String yamlFile, ILogger logger)
{
//Stream the input file
StreamReader streamReader = new StreamReader(yamlFile);
Load(streamReader);
Load(streamReader, logger);
}

/*
* Loading YAML file
*/
public static void Load(StreamReader streamReader)
public static void Load(StreamReader streamReader, ILogger logger)
{

//Load the stream
Expand Down Expand Up @@ -94,7 +93,7 @@ public static void Load(StreamReader streamReader)
}

}
log.Info("Loaded configuration for eBay oAuth Token");
logger.LogInformation("Loaded configuration for eBay oAuth Token");

}

Expand Down
18 changes: 12 additions & 6 deletions ebay-oauth-csharp-client/eBay/ApiClient/Auth/OAuth2/OAuth2Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@
using System.Net;
using Newtonsoft.Json;
using System.Text;
using log4net;
using Microsoft.Extensions.Logging;

namespace eBay.ApiClient.Auth.OAuth2
{
public class OAuth2Api
{
private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private readonly ILogger<OAuth2Api> logger;

public OAuth2Api(ILogger<OAuth2Api> logger)
{
this.logger = logger;
}

private static AppTokenCache appTokenCache = new AppTokenCache();

private class AppTokenCache
Expand Down Expand Up @@ -88,7 +94,7 @@ public OAuthResponse GetApplicationToken(OAuthEnvironment environment, IList<Str
oAuthResponse = appTokenCache.GetValue(environment);
if (oAuthResponse != null && oAuthResponse.AccessToken != null && oAuthResponse.AccessToken.Token != null)
{
log.Info("Returning token from cache for " + environment.ConfigIdentifier());
logger.LogInformation("Returning token from cache for " + environment.ConfigIdentifier());
return oAuthResponse;
}
}
Expand Down Expand Up @@ -151,7 +157,7 @@ public String GenerateUserAuthorizationUrl(OAuthEnvironment environment, IList<S

sb.Append(OAuth2Util.CreateRequestPayload(queryParams));

log.Debug("Authorization url " + sb);
logger.LogDebug("Authorization url " + sb);
return sb.ToString();
}

Expand Down Expand Up @@ -280,7 +286,7 @@ public OAuthResponse HandleApiResponse(RestResponse response, TokenType tokenTyp
if (response.StatusCode != HttpStatusCode.OK)
{
oAuthResponse.ErrorMessage = response.Content;
log.Error("Error in fetching the token. Error:" + oAuthResponse.ErrorMessage);
logger.LogError("Error in fetching the token. Error:" + oAuthResponse.ErrorMessage);
}
else
{
Expand All @@ -306,7 +312,7 @@ public OAuthResponse HandleApiResponse(RestResponse response, TokenType tokenTyp
oAuthResponse.RefreshToken = refreshToken;
}
}
log.Info("Fetched the token successfully from API");
logger.LogInformation("Fetched the token successfully from API");
return oAuthResponse;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ebay-oauth-csharp-client/ebay-oauth-csharp-client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<Folder Include="eBay\ApiClient\Auth\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
<PackageReference Include="YamlDotNet" Version="13.1.1" />
<PackageReference Include="RestSharp" Version="112.0.0" />
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion ebay-oauth-csharp-client/ebay-oauth-csharp-client.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<group targetFramework="net6.0">
<dependency id="YamlDotNet" version="13.1.1" />
<dependency id="RestSharp" version="110.2.0" />
<dependency id="log4net" version="2.0.15" />
<dependency id="Microsoft.Extensions.Logging.Abstractions" version="9.0.0" />
<dependency id="Newtonsoft.Json" version="13.0.3" />
</group>
</dependencies>
Expand Down