@@ -39,4 +39,42 @@ public static function getAccessTokenFromRefreshToken($refreshToken, $clientId,
39
39
40
40
return $ bodyAsJson ['access_token ' ];
41
41
}
42
+
43
+ /**
44
+ * @param string $lwaAuthorizationCode
45
+ * @param string $clientId
46
+ * @param string $clientSecret
47
+ * @param string $redirectUri
48
+ * @return string|null
49
+ * @throws GuzzleException
50
+ */
51
+ public static function getRefreshTokenFromLwaAuthorizationCode (
52
+ string $ lwaAuthorizationCode ,
53
+ string $ clientId ,
54
+ string $ clientSecret ,
55
+ string $ redirectUri
56
+ ): ?string {
57
+ $ client = new Client ();
58
+ $ params = [
59
+ 'grant_type ' => 'authorization_code ' ,
60
+ 'client_id ' => $ clientId ,
61
+ 'client_secret ' => $ clientSecret ,
62
+ 'code ' => $ lwaAuthorizationCode ,
63
+ 'redirect_uri ' => $ redirectUri ,
64
+ ];
65
+ $ options = array_merge ([
66
+ RequestOptions::HEADERS => ['Accept ' => 'application/json ' ],
67
+ RequestOptions::HTTP_ERRORS => false ,
68
+ 'curl ' => [
69
+ CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1_2,
70
+ ],
71
+ ], $ params ? [RequestOptions::FORM_PARAMS => $ params ] : []);
72
+
73
+ $ response = $ client ->request ('POST ' , 'https://api.amazon.com/auth/o2/token ' , $ options );
74
+
75
+ $ body = $ response ->getBody ()->getContents ();
76
+ $ bodyAsJson = json_decode ($ body , true );
77
+
78
+ return $ bodyAsJson ['refresh_token ' ];
79
+ }
42
80
}
0 commit comments