Skip to content

Commit

Permalink
Add argument checks
Browse files Browse the repository at this point in the history
Check if arguments are null or empty.
  • Loading branch information
vanillajonathan committed Dec 1, 2021
1 parent efb6839 commit 493c646
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions FortnoxSDK/Auth/StandardAuthWorkflow.cs
Expand Up @@ -29,6 +29,15 @@ public TokenInfo GetToken(string authCode, string clientId, string clientSecret,

public async Task<TokenInfo> GetTokenAsync(string authCode, string clientId, string clientSecret, string redirectUri = null)
{
if (string.IsNullOrEmpty(authCode))
throw new ArgumentException("Argument is null or empty.", nameof(authCode));

if (string.IsNullOrEmpty(clientId))
throw new ArgumentException("Argument is null or empty.", nameof(clientId));

if (string.IsNullOrEmpty(clientSecret))
throw new ArgumentException("Argument is null or empty.", nameof(clientSecret));

var credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{clientId}:{clientSecret}"));

var request = new HttpRequestMessage(HttpMethod.Post, AuthTokenUri);
Expand Down Expand Up @@ -56,6 +65,15 @@ public TokenInfo RefreshToken(string refreshToken, string clientId, string clien

public async Task<TokenInfo> RefreshTokenAsync(string refreshToken, string clientId, string clientSecret)
{
if (string.IsNullOrEmpty(refreshToken))
throw new ArgumentException("Argument is null or empty.", nameof(refreshToken));

if (string.IsNullOrEmpty(clientId))
throw new ArgumentException("Argument is null or empty.", nameof(clientId));

if (string.IsNullOrEmpty(clientSecret))
throw new ArgumentException("Argument is null or empty.", nameof(clientSecret));

var credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{clientId}:{clientSecret}"));

var request = new HttpRequestMessage(HttpMethod.Post, AuthTokenUri);
Expand Down

0 comments on commit 493c646

Please sign in to comment.