Skip to content

Commit 21ad4f0

Browse files
authored
Merge pull request #196 from umbraco/feature/shopify-oauth
Shopify OAuth fixes
2 parents f86aacb + 63eeb74 commit 21ad4f0

File tree

7 files changed

+39
-20
lines changed

7 files changed

+39
-20
lines changed

src/Umbraco.Cms.Integrations.Commerce.Shopify/App_Plugins/UmbracoCms.Integrations/Commerce/Shopify/js/productPickerSettings.controller.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@
6262

6363
function validateOAuthSetup() {
6464
umbracoCmsIntegrationsCommerceShopifyResource.validateAccessToken().then(function (response) {
65-
6665
vm.oauthSetup = {
67-
isConnected: response.isValid,
66+
isValid: response.isValid,
67+
isConnected: response.isConnected,
6868
isAccessTokenExpired: response.isExpired,
69-
isAccessTokenValid: response.isValid
69+
isAccessTokenValid: response.isConnected
7070
}
7171

7272
if (vm.oauthSetup.isConnected === true && vm.oauthSetup.isAccessTokenValid === true) {

src/Umbraco.Cms.Integrations.Commerce.Shopify/Controllers/ProductsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public ProductsController(IShopifyService apiService, AuthorizationImplementatio
5050
}
5151

5252
[HttpGet]
53-
public EditorSettings CheckConfiguration() => _apiService.GetApiConfiguration();
53+
public async Task<EditorSettings> CheckConfiguration() => await _apiService.GetApiConfiguration();
5454

5555
[HttpGet]
5656
public string GetAuthorizationUrl() => _authorizationService.GetAuthorizationUrl();

src/Umbraco.Cms.Integrations.Commerce.Shopify/Models/EditorSettings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ public EditorSettings()
1212
[JsonProperty("isValid")]
1313
public bool IsValid { get; set; }
1414

15+
[JsonProperty("isConnected")]
16+
public bool IsConnected { get; set; }
17+
1518
[JsonProperty("type")]
1619
public ConfigurationType Type { get; set; }
1720
}

src/Umbraco.Cms.Integrations.Commerce.Shopify/Services/BaseAuthorizationService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ public class BaseAuthorizationService
1616
protected const string ShopifyAuthorizationUrl = "https://{0}.myshopify.com/admin/oauth/authorize" +
1717
"?client_id={1}" +
1818
"&redirect_uri={2}" +
19-
"&scope=read_products" +
20-
"&grant_options[]=value";
19+
"&scope=read_products";
2120

2221
public BaseAuthorizationService(ITokenService tokenService)
2322
{

src/Umbraco.Cms.Integrations.Commerce.Shopify/Services/IShopifyService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Umbraco.Cms.Integrations.Commerce.Shopify.Services
77
{
88
public interface IShopifyService
99
{
10-
EditorSettings GetApiConfiguration();
10+
Task<EditorSettings> GetApiConfiguration();
1111

1212
Task<ResponseDto<ProductsListDto>> ValidateAccessToken();
1313

src/Umbraco.Cms.Integrations.Commerce.Shopify/Services/ShopifyService.cs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public ShopifyService(ILogger logger, ITokenService tokenService)
9393
}
9494
#endif
9595

96-
public EditorSettings GetApiConfiguration()
96+
public async Task<EditorSettings> GetApiConfiguration()
9797
{
9898
if (string.IsNullOrEmpty(_settings.Shop)
9999
|| string.IsNullOrEmpty(_settings.ApiVersion))
@@ -105,14 +105,27 @@ public EditorSettings GetApiConfiguration()
105105

106106
// validate OAuth configuration if AuthorizationService is used.
107107
// if authorization is managed through UmbracoAuthorizationService, the properties client ID and proxy URL are set correctly.
108+
var accessTokenValidationResponse = await ValidateAccessToken();
108109
if (_settings.UseUmbracoAuthorization)
109-
return new EditorSettings { IsValid = true, Type = ConfigurationType.OAuth };
110+
{
111+
var editorSettings = new EditorSettings { IsValid = true, Type = ConfigurationType.OAuth };
112+
113+
editorSettings.IsConnected = accessTokenValidationResponse.IsValid;
114+
115+
return editorSettings;
116+
}
110117
else
118+
{
111119
return !string.IsNullOrEmpty(_oauthSettings.ClientId)
112120
&& !string.IsNullOrEmpty(_oauthSettings.ClientSecret)
113121
&& !string.IsNullOrEmpty(_oauthSettings.RedirectUri)
114-
? new EditorSettings { IsValid = true, Type = ConfigurationType.OAuth }
122+
? new EditorSettings {
123+
IsValid = true,
124+
IsConnected = accessTokenValidationResponse.IsValid,
125+
Type = ConfigurationType.OAuth
126+
}
115127
: new EditorSettings();
128+
}
116129
}
117130

118131
public async Task<ResponseDto<ProductsListDto>> ValidateAccessToken()
@@ -146,13 +159,15 @@ public async Task<ResponseDto<ProductsListDto>> ValidateAccessToken()
146159

147160
public void RevokeAccessToken()
148161
{
149-
_tokenService.RemoveParameters(Constants.Configuration.UmbracoCmsIntegrationsCommerceShopifyAccessToken);
162+
_tokenService.RemoveParameters(Constants.AccessTokenDbKey);
150163
}
151164

152165
public async Task<ResponseDto<ProductsListDto>> GetResults(string pageInfo)
153166
{
154167
string accessToken;
155-
if (GetApiConfiguration().Type.Value == ConfigurationType.OAuth.Value)
168+
169+
var apiConfiguration = await GetApiConfiguration();
170+
if (apiConfiguration.Type.Value == ConfigurationType.OAuth.Value)
156171
_tokenService.TryGetParameters(Constants.AccessTokenDbKey, out accessToken);
157172
else
158173
{
@@ -210,7 +225,8 @@ public async Task<ResponseDto<ProductsListDto>> GetResults(string pageInfo)
210225
public async Task<ResponseDto<ProductsListDto>> GetProductsByIds(long[] ids)
211226
{
212227
string accessToken;
213-
if (GetApiConfiguration().Type.Value == ConfigurationType.OAuth.Value)
228+
var apiConfiguration = await GetApiConfiguration();
229+
if (apiConfiguration.Type.Value == ConfigurationType.OAuth.Value)
214230
_tokenService.TryGetParameters(Constants.AccessTokenDbKey, out accessToken);
215231
else
216232
{
@@ -260,7 +276,8 @@ public async Task<ResponseDto<ProductsListDto>> GetProductsByIds(long[] ids)
260276
public async Task<int> GetCount()
261277
{
262278
string accessToken;
263-
if (GetApiConfiguration().Type.Value == ConfigurationType.OAuth.Value)
279+
var apiConfiguration = await GetApiConfiguration();
280+
if (apiConfiguration.Type.Value == ConfigurationType.OAuth.Value)
264281
_tokenService.TryGetParameters(Constants.AccessTokenDbKey, out accessToken);
265282
else
266283
{

src/Umbraco.Cms.Integrations.Commerce.Shopify/Umbraco.Cms.Integrations.Commerce.Shopify.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net472;net50;net60;net70;net80</TargetFrameworks>
3+
<TargetFrameworks>net472;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
44
</PropertyGroup>
55

66
<PropertyGroup>
@@ -10,7 +10,7 @@
1010
<PackageIconUrl></PackageIconUrl>
1111
<PackageProjectUrl>https://github.com/umbraco/Umbraco.Cms.Integrations/blob/main/src/Umbraco.Cms.Integrations.Commerce.Shopify</PackageProjectUrl>
1212
<RepositoryUrl>https://github.com/umbraco/Umbraco.Cms.Integrations</RepositoryUrl>
13-
<Version>1.2.0</Version>
13+
<Version>1.2.1</Version>
1414
<Authors>Umbraco HQ</Authors>
1515
<Company>Umbraco</Company>
1616
<PackageTags>Umbraco;Umbraco-Marketplace</PackageTags>
@@ -22,22 +22,22 @@
2222
<PackageReference Include="UmbracoCms.Web" version="8.5.4" />
2323
</ItemGroup>
2424

25-
<ItemGroup Condition="'$(TargetFramework)' == 'net50'">
25+
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
2626
<PackageReference Include="Umbraco.Cms.Web.Website" version="[9.0.1,10)" />
2727
<PackageReference Include="Umbraco.Cms.Web.BackOffice" version="[9.0.1,10)" />
2828
</ItemGroup>
2929

30-
<ItemGroup Condition="'$(TargetFramework)' == 'net60'">
30+
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
3131
<PackageReference Include="Umbraco.Cms.Web.Website" version="[10.0.0,11)" />
3232
<PackageReference Include="Umbraco.Cms.Web.BackOffice" version="[10.0.0,11)" />
3333
</ItemGroup>
3434

35-
<ItemGroup Condition="'$(TargetFramework)' == 'net70'">
35+
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
3636
<PackageReference Include="Umbraco.Cms.Web.Website" version="[11.0.0,13)" />
3737
<PackageReference Include="Umbraco.Cms.Web.BackOffice" version="[11.0.0,13)" />
3838
</ItemGroup>
3939

40-
<ItemGroup Condition="'$(TargetFramework)' == 'net80'">
40+
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
4141
<PackageReference Include="Umbraco.Cms.Web.Website" version="[13.0.0,14)" />
4242
<PackageReference Include="Umbraco.Cms.Web.BackOffice" version="[13.0.0,14)" />
4343
</ItemGroup>

0 commit comments

Comments
 (0)