99namespace Microsoft \Graph \Core \Authentication ;
1010
1111
12- use InvalidArgumentException ;
1312use Microsoft \Graph \Core \NationalCloud ;
13+ use Microsoft \Kiota \Authentication \Cache \AccessTokenCache ;
1414use Microsoft \Kiota \Authentication \Oauth \ProviderFactory ;
1515use Microsoft \Kiota \Authentication \Oauth \TokenRequestContext ;
1616use Microsoft \Kiota \Authentication \PhpLeagueAccessTokenProvider ;
@@ -38,13 +38,16 @@ class GraphPhpLeagueAccessTokenProvider extends PhpLeagueAccessTokenProvider
3838 * @param array<string> $scopes if left empty, it's set to ["https://[graph national cloud host]/.default"] scope
3939 * @param string $nationalCloud Defaults to https://graph.microsoft.com. See
4040 * https://learn.microsoft.com/en-us/graph/deployments
41+ * @param AccessTokenCache|null $accessTokenCache Defaults to an in-memory cache if null
4142 */
4243 public function __construct (
4344 TokenRequestContext $ tokenRequestContext ,
4445 array $ scopes = [],
45- string $ nationalCloud = NationalCloud::GLOBAL
46+ string $ nationalCloud = NationalCloud::GLOBAL ,
47+ ?AccessTokenCache $ accessTokenCache = null
4648 )
4749 {
50+ $ nationalCloud = empty ($ nationalCloud ) ? NationalCloud::GLOBAL : $ nationalCloud ;
4851 $ allowedHosts = [
4952 "graph.microsoft.com " ,
5053 "graph.microsoft.us " ,
@@ -61,6 +64,24 @@ public function __construct(
6164 $ tokenBaseServiceUrl ,
6265 $ nationalCloud
6366 );
64- parent ::__construct ($ tokenRequestContext , $ scopes , $ allowedHosts , $ oauthProvider );
67+ parent ::__construct ($ tokenRequestContext , $ scopes , $ allowedHosts , $ oauthProvider , $ accessTokenCache );
68+ }
69+
70+ /**
71+ * Get an instance of GraphPhpLeagueAccessTokenProvider with a custom cache
72+ *
73+ * @param AccessTokenCache $accessTokenCache
74+ * @param TokenRequestContext $tokenRequestContext
75+ * @param array<string> $scopes
76+ * @return GraphPhpLeagueAccessTokenProvider
77+ */
78+ public static function createWithCache (
79+ AccessTokenCache $ accessTokenCache ,
80+ TokenRequestContext $ tokenRequestContext ,
81+ array $ scopes = []
82+ ): self
83+ {
84+ return new GraphPhpLeagueAccessTokenProvider (
85+ $ tokenRequestContext , $ scopes , NationalCloud::GLOBAL , $ accessTokenCache );
6586 }
6687}
0 commit comments