Skip to content

Commit 0be1010

Browse files
committed
Merge branch 'jwt_token'
2 parents 0900a9d + 5110811 commit 0be1010

33 files changed

+280
-178
lines changed

src/Api/ApiVersion.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,32 @@ namespace Aspose.BarCode.Cloud.Sdk
2828
/// <summary>
2929
/// The availiable api versions.
3030
/// </summary>
31-
public enum ApiVersion
31+
public class ApiVersion
3232
{
33+
public string Version { get; set; }
34+
private ApiVersion(string version)
35+
{
36+
Version = version;
37+
}
3338
/// <summary>
3439
/// Current API version
3540
/// </summary>
36-
V1 = 1,
41+
public static ApiVersion V1 = new ApiVersion("1.0");
3742

3843
/// <summary>
3944
/// Stable version
4045
/// </summary>
41-
V2 = 2,
46+
public static ApiVersion V2 = new ApiVersion("2.0");
4247

4348
/// <summary>
4449
/// Frozen version
4550
/// </summary>
46-
V3 = 3
51+
public static ApiVersion V3 = new ApiVersion("3.0");
52+
53+
public override string ToString()
54+
{
55+
return Version;
56+
}
4757
}
58+
4859
}

src/Api/AuthType.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ public enum AuthType
3838
/// <summary>
3939
/// Authentification with signing of url.
4040
/// </summary>
41-
RequestSignature = 1
41+
RequestSignature = 1,
42+
43+
/// <summary>
44+
/// Token for OAuth2 provided by caller
45+
/// </summary>
46+
ExternalAuth = 2,
47+
4248
}
4349
}

src/Api/BarCodeApi.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// --------------------------------------------------------------------------------------------------------------------
22
// <copyright company="Aspose" file="BarCodeApi.cs">
3-
// Copyright (c) 2018 Aspose.BarCode for Cloud
3+
// Copyright (c) 2019 Aspose.BarCode for Cloud
44
// </copyright>
55
// <summary>
66
// Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -53,6 +53,12 @@ public BarCodeApi(string apiKey, string appSid)
5353
{
5454
}
5555

56+
public BarCodeApi(string jwtToken)
57+
: this(new Configuration { JwtToken = jwtToken, ApiVersion = ApiVersion.V3, AuthType = AuthType.ExternalAuth })
58+
{
59+
}
60+
61+
5662
/// <summary>
5763
/// Initializes a new instance of the <see cref="BarCodeApi"/> class.
5864
/// </summary>
@@ -62,10 +68,18 @@ public BarCodeApi(Configuration configuration)
6268
this.configuration = configuration;
6369

6470
var requestHandlers = new List<IRequestHandler>();
65-
requestHandlers.Add(new OAuthRequestHandler(this.configuration));
71+
switch (this.configuration.AuthType)
72+
{
73+
case AuthType.RequestSignature: requestHandlers.Add(new AuthWithSignatureRequestHandler(this.configuration));
74+
break;
75+
case AuthType.OAuth2: requestHandlers.Add(new OAuthRequestHandler(this.configuration));
76+
break;
77+
case AuthType.ExternalAuth: requestHandlers.Add(new ExternalAuthorizationRequestHandler(this.configuration));
78+
break;
79+
}
80+
6681
requestHandlers.Add(new DebugLogRequestHandler(this.configuration));
6782
requestHandlers.Add(new ApiExceptionRequestHandler());
68-
requestHandlers.Add(new AuthWithSignatureRequestHandler(this.configuration));
6983
this.apiInvoker = new ApiInvoker(requestHandlers);
7084
}
7185

src/Api/Configuration.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ public class Configuration
4545
/// </summary>
4646
public string AppSid { get; set; }
4747

48+
/// <summary>
49+
/// Gets or sets the Jwt token.
50+
/// If set the library would handle auth internally
51+
/// </summary>
52+
public string JwtToken { get; set; }
53+
54+
4855
/// <summary>
4956
/// Gets or sets a value indicating whether debug mode.
5057
/// </summary>
@@ -70,7 +77,7 @@ public Configuration()
7077

7178
internal string GetApiRootUrl()
7279
{
73-
var result = this.ApiBaseUrl + "/v" + (int)ApiVersion;
80+
var result = this.ApiBaseUrl + "/v" + ApiVersion;
7481

7582
return result.EndsWith("/") ? result.Substring(0, result.Length - 1) : result;
7683
}

src/Aspose.BarCode.Cloud.Sdk.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ Aspose.Barcode for Cloud allows you to control all aspects of the image and barc
1010
<RepositoryUrl>https://github.com/aspose-barcode-cloud/aspose-barcode-cloud-dotnet</RepositoryUrl>
1111
<PackageTags>Aspose.Barcode barcode generation recognition Alpha-Numeric AI-8102-Coupon AustralianPosteParcel AustraliaPost Aztec Codabar CodablockF Code11 Code128 Code16K Code32 Code39Extended Code39Standard Code93Extended Code93Standard DatabarExpanded DatabarExpandedStacked DatabarLimited DatabarOmniDirectional DatabarStacked DatabarStackedOmniDirectional DatabarTruncated DataLogic2of5 DataMatrix DeutschePostIdentcode DeutschePostLeitcode DotCode DutchKIX EAN13 EAN14 EAN8 GS1CodablockF GS1Code128 GS1DataMatrix GS1QR IATA2of5 Interleaved2of5 ISBN ISMN ISSN ItalianPost25 ITF14 ITF6 MacroPdf417 Matrix2of5 MaxiCode MicroPdf417 MICR (only BarCode reader) MSI OneCode OPC PatchCode Pdf417 Pharmacode Planet Postnet PZN QR RM4SCC SCC14 SingaporePost SSCC18 Standard2of5 SwissPostParcel UPCA UpcaGs1Code128Coupon UpcaGs1DatabarCoupon UPCE VIN</PackageTags>
1212
<PackageLicenseUrl>https://github.com/aspose-barcode-cloud/aspose-barcode-cloud-dotnet/blob/master/LICENSE</PackageLicenseUrl>
13-
<Copyright>© Aspose 2002-2018. All Rights Reserved.</Copyright>
13+
<Copyright>© Aspose 2002-2019. All Rights Reserved.</Copyright>
1414
<RepositoryType>Git</RepositoryType>
1515
<PackageProjectUrl>https://github.com/aspose-barcode-cloud/aspose-barcode-cloud-dotnet</PackageProjectUrl>
1616
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1717
<PackageId>Aspose.BarCode-Cloud</PackageId>
1818
<Product>Aspose.BarCode Cloud SDK for .NET</Product>
1919
<PackageIconUrl>https://www.aspose.cloud/templates/aspose/App_Themes/V3/images/barcode/272x272/aspose_barcode-for-cloud-min.png</PackageIconUrl>
20-
<Version>18.6.0</Version>
20+
<Version>19.10.0</Version>
2121
<Authors>asposecloud</Authors>
22+
<AssemblyVersion>19.10.0.0</AssemblyVersion>
2223
</PropertyGroup>
2324

2425
<ItemGroup>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright company="Aspose" file="OAuthRequestHandler.cs">
3+
// Copyright (c) 2018 Aspose.BarCode for Cloud
4+
// </copyright>
5+
// <summary>
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
// </summary>
24+
// --------------------------------------------------------------------------------------------------------------------
25+
26+
namespace Aspose.BarCode.Cloud.Sdk.RequestHandlers
27+
{
28+
using System.Collections.Generic;
29+
using System.IO;
30+
using System.Net;
31+
32+
using Newtonsoft.Json;
33+
34+
internal class ExternalAuthorizationRequestHandler : IRequestHandler
35+
{
36+
private readonly Configuration configuration;
37+
38+
public ExternalAuthorizationRequestHandler(Configuration configuration)
39+
{
40+
this.configuration = configuration;
41+
}
42+
43+
public string ProcessUrl(string url)
44+
{
45+
return url;
46+
}
47+
48+
public void BeforeSend(WebRequest request, Stream streamToSend)
49+
{
50+
if (this.configuration.AuthType == AuthType.OAuth2 && string.IsNullOrEmpty(this.configuration.JwtToken))
51+
{
52+
throw new ApiException(401, "Authorization header value required");
53+
}
54+
55+
request.Headers.Add("Authorization", "Bearer " + this.configuration.JwtToken);
56+
}
57+
58+
public void ProcessResponse(HttpWebResponse response, Stream resultStream)
59+
{
60+
}
61+
62+
}
63+
}

0 commit comments

Comments
 (0)