@@ -35,7 +35,10 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
35
35
[ NotNull ] AuthenticationProperties properties ,
36
36
[ NotNull ] OAuthTokenResponse tokens )
37
37
{
38
- string uri = string . Format ( CultureInfo . InvariantCulture , ShopifyAuthenticationDefaults . UserInformationEndpointFormat , properties . Items [ ShopifyAuthenticationDefaults . ShopNameAuthenticationProperty ] ) ;
38
+ var uri = string . Format (
39
+ CultureInfo . InvariantCulture ,
40
+ ShopifyAuthenticationDefaults . UserInformationEndpointFormat ,
41
+ properties . Items [ ShopifyAuthenticationDefaults . ShopNameAuthenticationProperty ] ) ;
39
42
40
43
using var request = new HttpRequestMessage ( HttpMethod . Get , uri ) ;
41
44
request . Headers . Accept . Add ( new MediaTypeWithQualityHeaderValue ( "application/json" ) ) ;
@@ -52,23 +55,23 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
52
55
53
56
// In Shopify, the customer can modify the scope given to the app. Apps should verify
54
57
// that the customer is allowing the required scope.
55
- string actualScope = tokens . Response ! . RootElement . GetString ( "scope" ) ?? string . Empty ;
56
- bool isPersistent = true ;
58
+ var actualScope = tokens . Response ! . RootElement . GetString ( "scope" ) ?? string . Empty ;
59
+ var isPersistent = true ;
57
60
58
61
// If the request was for a "per-user" (i.e. no offline access)
59
62
if ( tokens . Response . RootElement . TryGetProperty ( "expires_in" , out var expiresInProperty ) )
60
63
{
61
64
isPersistent = false ;
62
65
63
- if ( expiresInProperty . TryGetInt32 ( out int expiresIn ) )
66
+ if ( expiresInProperty . TryGetInt32 ( out var expiresIn ) )
64
67
{
65
68
var expires = Clock . UtcNow . AddSeconds ( expiresIn ) ;
66
69
identity . AddClaim ( new Claim ( ClaimTypes . Expiration , expires . ToString ( "O" , CultureInfo . InvariantCulture ) , ClaimValueTypes . DateTime ) ) ;
67
70
}
68
71
69
72
actualScope = tokens . Response . RootElement . GetString ( "associated_user_scope" ) ?? string . Empty ;
70
73
71
- string userData = tokens . Response . RootElement . GetString ( "associated_user" ) ?? string . Empty ;
74
+ var userData = tokens . Response . RootElement . GetString ( "associated_user" ) ?? string . Empty ;
72
75
identity . AddClaim ( new Claim ( ClaimTypes . UserData , userData ) ) ;
73
76
}
74
77
@@ -94,16 +97,16 @@ protected override string FormatScope([NotNull] IEnumerable<string> scopes)
94
97
/// <inheritdoc />
95
98
protected override string BuildChallengeUrl ( [ NotNull ] AuthenticationProperties properties , [ NotNull ] string redirectUri )
96
99
{
97
- if ( ! properties . Items . TryGetValue ( ShopifyAuthenticationDefaults . ShopNameAuthenticationProperty , out string ? shopName ) )
100
+ if ( ! properties . Items . TryGetValue ( ShopifyAuthenticationDefaults . ShopNameAuthenticationProperty , out var shopName ) )
98
101
{
99
102
Log . ShopNameMissing ( Logger ) ;
100
103
throw new InvalidOperationException ( "Shopify provider AuthenticationProperties must contain ShopNameAuthenticationProperty." ) ;
101
104
}
102
105
103
- string authorizationEndpoint = string . Format ( CultureInfo . InvariantCulture , Options . AuthorizationEndpoint , shopName ) ;
106
+ var authorizationEndpoint = string . Format ( CultureInfo . InvariantCulture , Options . AuthorizationEndpoint , shopName ) ;
104
107
105
108
// Get the permission scope, which can either be set in options or overridden in AuthenticationProperties.
106
- if ( ! properties . Items . TryGetValue ( ShopifyAuthenticationDefaults . ShopScopeAuthenticationProperty , out string ? scope ) )
109
+ if ( ! properties . Items . TryGetValue ( ShopifyAuthenticationDefaults . ShopScopeAuthenticationProperty , out var scope ) )
107
110
{
108
111
var scopeParameter = properties . GetParameter < ICollection < string > > ( OAuthChallengeProperties . ScopeKey ) ;
109
112
scope = scopeParameter != null ? FormatScope ( scopeParameter ) : FormatScope ( ) ;
@@ -118,23 +121,23 @@ protected override string BuildChallengeUrl([NotNull] AuthenticationProperties p
118
121
119
122
if ( Options . UsePkce )
120
123
{
121
- byte [ ] bytes = RandomNumberGenerator . GetBytes ( 256 / 8 ) ;
122
- string codeVerifier = WebEncoders . Base64UrlEncode ( bytes ) ;
124
+ var bytes = RandomNumberGenerator . GetBytes ( 256 / 8 ) ;
125
+ var codeVerifier = WebEncoders . Base64UrlEncode ( bytes ) ;
123
126
124
127
// Store this for use during the code redemption.
125
128
properties . Items . Add ( OAuthConstants . CodeVerifierKey , codeVerifier ) ;
126
129
127
- byte [ ] challengeBytes = SHA256 . HashData ( Encoding . UTF8 . GetBytes ( codeVerifier ) ) ;
130
+ var challengeBytes = SHA256 . HashData ( Encoding . UTF8 . GetBytes ( codeVerifier ) ) ;
128
131
parameters [ OAuthConstants . CodeChallengeKey ] = WebEncoders . Base64UrlEncode ( challengeBytes ) ;
129
132
parameters [ OAuthConstants . CodeChallengeMethodKey ] = OAuthConstants . CodeChallengeMethodS256 ;
130
133
}
131
134
132
135
parameters [ "state" ] = Options . StateDataFormat . Protect ( properties ) ;
133
136
134
- string challengeUrl = QueryHelpers . AddQueryString ( authorizationEndpoint , parameters ) ;
137
+ var challengeUrl = QueryHelpers . AddQueryString ( authorizationEndpoint , parameters ) ;
135
138
136
139
// If we're requesting a per-user, online only, token, add the grant_options query param.
137
- if ( properties . Items . TryGetValue ( ShopifyAuthenticationDefaults . GrantOptionsAuthenticationProperty , out string ? grantOptions ) &&
140
+ if ( properties . Items . TryGetValue ( ShopifyAuthenticationDefaults . GrantOptionsAuthenticationProperty , out var grantOptions ) &&
138
141
grantOptions == ShopifyAuthenticationDefaults . PerUserAuthenticationPropertyValue )
139
142
{
140
143
challengeUrl = QueryHelpers . AddQueryString ( challengeUrl , "grant_options[]" , ShopifyAuthenticationDefaults . PerUserAuthenticationPropertyValue ) ;
@@ -167,7 +170,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
167
170
var shopValue = Context . Request . Query [ "shop" ] ;
168
171
var stateValue = Context . Request . Query [ "state" ] ;
169
172
170
- string shop = shopValue . ToString ( ) ;
173
+ var shop = shopValue . ToString ( ) ;
171
174
172
175
// Shop name must end with myshopify.com
173
176
if ( ! shop . EndsWith ( ".myshopify.com" , StringComparison . OrdinalIgnoreCase ) )
@@ -182,7 +185,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
182
185
// request the token. This probably isn't necessary, but it's an easy extra verification.
183
186
var authenticationProperties = Options . StateDataFormat . Unprotect ( stateValue ) ;
184
187
185
- string ? shopNamePropertyValue = authenticationProperties ? . Items [ ShopifyAuthenticationDefaults . ShopNameAuthenticationProperty ] ;
188
+ var shopNamePropertyValue = authenticationProperties ? . Items [ ShopifyAuthenticationDefaults . ShopNameAuthenticationProperty ] ;
186
189
187
190
if ( ! string . Equals ( shopNamePropertyValue , shopDns , StringComparison . OrdinalIgnoreCase ) )
188
191
{
@@ -195,7 +198,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
195
198
return OAuthTokenResponse . Failed ( ex ) ;
196
199
}
197
200
198
- string uri = string . Format ( CultureInfo . InvariantCulture , Options . TokenEndpoint , shopDns ) ;
201
+ var uri = string . Format ( CultureInfo . InvariantCulture , Options . TokenEndpoint , shopDns ) ;
199
202
200
203
using var request = new HttpRequestMessage ( HttpMethod . Post , uri ) ;
201
204
request . Headers . Accept . Add ( new MediaTypeWithQualityHeaderValue ( "application/x-www-form-urlencoded" ) ) ;
0 commit comments