Skip to content

Commit 588ecf4

Browse files
committed
Applying comments from review
1 parent db1ee7a commit 588ecf4

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

src/Auth/OAuth.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class OAuth
3535
public const ACCESS_TOKEN_POST_PATH = '/admin/oauth/access_token';
3636

3737
/**
38-
* Initializes a session and cookie for the OAuth process, and returns the authorization url
38+
* Begins the OAuth process by setting the appropriate cookies, and returns the authorization url
3939
*
4040
* @param string $shop A Shopify domain name or hostname
4141
* @param string $redirectPath Redirect path for callback
@@ -68,7 +68,7 @@ public static function begin(
6868

6969
$state = Uuid::uuid4()->toString();
7070

71-
$cookieSet = self::setCookieState($setCookieFunction, $state, strtotime('+1 minute'));
71+
$cookieSet = self::setStateCookie($setCookieFunction, $state, strtotime('+1 minute'));
7272
if (!$cookieSet) {
7373
throw new CookieSetException(
7474
'OAuth Cookie could not be saved.'
@@ -116,7 +116,7 @@ public static function callback(array $cookies, array $query, ?callable $setCook
116116
Context::throwIfUninitialized();
117117
Context::throwIfPrivateApp('OAuth is not allowed for private apps');
118118

119-
$cookieState = self::getCookieState($cookies);
119+
$cookieState = self::getStateCookie($cookies);
120120
if (!self::isCallbackQueryValid($query, $cookieState)) {
121121
throw new InvalidOAuthException('Invalid OAuth callback.');
122122
}
@@ -153,12 +153,12 @@ public static function callback(array $cookies, array $query, ?callable $setCook
153153
}
154154

155155
$sessionExpiration = ($session->getExpires() ? (int)$session->getExpires()->format('U') : null);
156-
$cookieSet = self::setCookieSessionId(
156+
$cookieSet = self::setSessionIdCookie(
157157
$setCookieFunction,
158158
$session->getId(),
159159
Context::$IS_EMBEDDED_APP ? time() : $sessionExpiration
160160
);
161-
$cookieSet = $cookieSet && self::setCookieState($setCookieFunction, $cookieState, time());
161+
$cookieSet = $cookieSet && self::setStateCookie($setCookieFunction, $cookieState, time());
162162

163163
if (!$cookieSet) {
164164
throw new CookieSetException('OAuth Cookie could not be saved.');
@@ -231,7 +231,7 @@ public static function getCurrentSessionId(array $rawHeaders, array $cookies, bo
231231
if (!$cookies) {
232232
throw new CookieNotFoundException('Could not find the current session id in the cookies');
233233
}
234-
$currentSessionId = self::getCookieSessionId($cookies);
234+
$currentSessionId = self::getSessionIdCookie($cookies);
235235
}
236236

237237
return $currentSessionId;
@@ -245,7 +245,7 @@ public static function getCurrentSessionId(array $rawHeaders, array $cookies, bo
245245
* @return string The state for the current OAuth process
246246
* @throws CookieNotFoundException
247247
*/
248-
private static function getCookieState(array $cookies): string
248+
private static function getStateCookie(array $cookies): string
249249
{
250250
$value = self::getCookie($cookies, self::STATE_COOKIE_NAME, self::STATE_SIG_COOKIE_NAME);
251251
if (!$value) {
@@ -266,7 +266,7 @@ private static function getCookieState(array $cookies): string
266266
*
267267
* @return bool Whether the cookie was successfully set
268268
*/
269-
private static function setCookieState(?callable $setCookieFunction, $state, $expiration): bool
269+
private static function setStateCookie(?callable $setCookieFunction, $state, $expiration): bool
270270
{
271271
$signature = hash_hmac('sha256', $state, Context::$API_SECRET_KEY);
272272
$signatureCookie = new OAuthCookie($signature, self::STATE_SIG_COOKIE_NAME, $expiration, true, true);
@@ -283,7 +283,7 @@ private static function setCookieState(?callable $setCookieFunction, $state, $ex
283283
* @return string The ID of the current session
284284
* @throws CookieNotFoundException
285285
*/
286-
private static function getCookieSessionId(array $cookies): string
286+
private static function getSessionIdCookie(array $cookies): string
287287
{
288288
$sessionId = self::getCookie($cookies, self::SESSION_ID_COOKIE_NAME, self::SESSION_ID_SIG_COOKIE_NAME);
289289
if (!$sessionId) {
@@ -302,7 +302,7 @@ private static function getCookieSessionId(array $cookies): string
302302
*
303303
* @return bool Whether the cookie was successfully set
304304
*/
305-
private static function setCookieSessionId(?callable $setCookieFunction, $sessionId, $expiration): bool
305+
private static function setSessionIdCookie(?callable $setCookieFunction, $sessionId, $expiration): bool
306306
{
307307
$signature = hash_hmac('sha256', $sessionId, Context::$API_SECRET_KEY);
308308
$signatureCookie = new OAuthCookie($signature, self::SESSION_ID_SIG_COOKIE_NAME, $expiration, true, true);

0 commit comments

Comments
 (0)