Skip to content

Commit 14db20f

Browse files
Merge pull request #64 from FusionAuth/lyle/ENG-3375/introspect-and-libs
Lyle/eng 3375/introspect and libs
2 parents 856a907 + 60d6132 commit 14db20f

1 file changed

Lines changed: 303 additions & 0 deletions

File tree

src/FusionAuth/FusionAuthClient.php

Lines changed: 303 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,29 @@ public function approveDevice($client_id, $client_secret, $token, $user_code)
144144
->go();
145145
}
146146

147+
/**
148+
* Approve a device grant.
149+
*
150+
* @param array $request The request object containing the device approval information and optional tenantId.
151+
*
152+
* @return ClientResponse The ClientResponse.
153+
* @throws \Exception
154+
*/
155+
public function approveDeviceWithRequest($request)
156+
{
157+
$post_data = array(
158+
'client_id' => $request->client_id
159+
,'client_secret' => $request->client_secret
160+
,'tenantId' => ($request->tenantId !== null ? (string)$request->tenantId : null)
161+
,'token' => $request->token
162+
,'user_code' => $request->user_code
163+
);
164+
return $this->start()->uri("/oauth2/device/approve")
165+
->bodyHandler(new FormDataBodyHandler($post_data))
166+
->post()
167+
->go();
168+
}
169+
147170
/**
148171
* Cancels the user action.
149172
*
@@ -443,6 +466,29 @@ public function clientCredentialsGrant($client_id, $client_secret, $scope = NULL
443466
->go();
444467
}
445468

469+
/**
470+
* Make a Client Credentials grant request to obtain an access token.
471+
*
472+
* @param array $request The client credentials grant request containing client authentication, scope and optional tenantId.
473+
*
474+
* @return ClientResponse The ClientResponse.
475+
* @throws \Exception
476+
*/
477+
public function clientCredentialsGrantWithRequest($request)
478+
{
479+
$post_data = array(
480+
'client_id' => $request->client_id
481+
,'client_secret' => $request->client_secret
482+
,'grant_type' => $request->grant_type
483+
,'scope' => $request->scope
484+
,'tenantId' => $request->tenantId
485+
);
486+
return $this->startAnonymous()->uri("/oauth2/token")
487+
->bodyHandler(new FormDataBodyHandler($post_data))
488+
->post()
489+
->go();
490+
}
491+
446492
/**
447493
* Adds a comment to the user's account.
448494
*
@@ -1788,6 +1834,51 @@ public function deleteWebhook($webhookId)
17881834
->go();
17891835
}
17901836

1837+
/**
1838+
* Start the Device Authorization flow using form-encoded parameters
1839+
*
1840+
* @param string $client_id The unique client identifier. The client Id is the Id of the FusionAuth Application in which you are attempting to authenticate.
1841+
* @param string $client_secret (Optional) The client secret. This value may optionally be provided in the request body instead of the Authorization header.
1842+
* @param string $scope (Optional) A space-delimited string of the requested scopes. Defaults to all scopes configured in the Application's OAuth configuration.
1843+
*
1844+
* @return ClientResponse The ClientResponse.
1845+
* @throws \Exception
1846+
*/
1847+
public function deviceAuthorize($client_id, $client_secret, $scope = NULL)
1848+
{
1849+
$post_data = array(
1850+
'client_id' => $client_id,
1851+
'client_secret' => $client_secret,
1852+
'scope' => $scope
1853+
);
1854+
return $this->startAnonymous()->uri("/oauth2/device_authorize")
1855+
->bodyHandler(new FormDataBodyHandler($post_data))
1856+
->post()
1857+
->go();
1858+
}
1859+
1860+
/**
1861+
* Start the Device Authorization flow using a request body
1862+
*
1863+
* @param array $request The device authorization request containing client authentication, scope, and optional device metadata.
1864+
*
1865+
* @return ClientResponse The ClientResponse.
1866+
* @throws \Exception
1867+
*/
1868+
public function deviceAuthorizeWithRequest($request)
1869+
{
1870+
$post_data = array(
1871+
'client_id' => $request->client_id
1872+
,'client_secret' => $request->client_secret
1873+
,'scope' => $request->scope
1874+
,'tenantId' => ($request->tenantId !== null ? (string)$request->tenantId : null)
1875+
);
1876+
return $this->startAnonymous()->uri("/oauth2/device_authorize")
1877+
->bodyHandler(new FormDataBodyHandler($post_data))
1878+
->post()
1879+
->go();
1880+
}
1881+
17911882
/**
17921883
* Disable two-factor authentication for a user.
17931884
*
@@ -1902,6 +1993,57 @@ public function exchangeOAuthCodeForAccessTokenUsingPKCE($code, $client_id, $cli
19021993
->go();
19031994
}
19041995

1996+
/**
1997+
* Exchanges an OAuth authorization code and code_verifier for an access token.
1998+
* Makes a request to the Token endpoint to exchange the authorization code returned from the Authorize endpoint and a code_verifier for an access token.
1999+
*
2000+
* @param array $request The PKCE OAuth code access token exchange request.
2001+
*
2002+
* @return ClientResponse The ClientResponse.
2003+
* @throws \Exception
2004+
*/
2005+
public function exchangeOAuthCodeForAccessTokenUsingPKCEWithRequest($request)
2006+
{
2007+
$post_data = array(
2008+
'client_id' => $request->client_id
2009+
,'client_secret' => $request->client_secret
2010+
,'code' => $request->code
2011+
,'code_verifier' => $request->code_verifier
2012+
,'grant_type' => $request->grant_type
2013+
,'redirect_uri' => $request->redirect_uri
2014+
,'tenantId' => ($request->tenantId !== null ? (string)$request->tenantId : null)
2015+
);
2016+
return $this->startAnonymous()->uri("/oauth2/token")
2017+
->bodyHandler(new FormDataBodyHandler($post_data))
2018+
->post()
2019+
->go();
2020+
}
2021+
2022+
/**
2023+
* Exchanges an OAuth authorization code for an access token.
2024+
* Makes a request to the Token endpoint to exchange the authorization code returned from the Authorize endpoint for an access token.
2025+
*
2026+
* @param array $request The OAuth code access token exchange request.
2027+
*
2028+
* @return ClientResponse The ClientResponse.
2029+
* @throws \Exception
2030+
*/
2031+
public function exchangeOAuthCodeForAccessTokenWithRequest($request)
2032+
{
2033+
$post_data = array(
2034+
'client_id' => $request->client_id
2035+
,'client_secret' => $request->client_secret
2036+
,'code' => $request->code
2037+
,'grant_type' => $request->grant_type
2038+
,'redirect_uri' => $request->redirect_uri
2039+
,'tenantId' => $request->tenantId
2040+
);
2041+
return $this->startAnonymous()->uri("/oauth2/token")
2042+
->bodyHandler(new FormDataBodyHandler($post_data))
2043+
->post()
2044+
->go();
2045+
}
2046+
19052047
/**
19062048
* Exchange a Refresh Token for an Access Token.
19072049
* If you will be using the Refresh Token Grant, you will make a request to the Token endpoint to exchange the user’s refresh token for an access token.
@@ -1932,6 +2074,32 @@ public function exchangeRefreshTokenForAccessToken($refresh_token, $client_id, $
19322074
->go();
19332075
}
19342076

2077+
/**
2078+
* Exchange a Refresh Token for an Access Token.
2079+
* If you will be using the Refresh Token Grant, you will make a request to the Token endpoint to exchange the user’s refresh token for an access token.
2080+
*
2081+
* @param array $request The refresh token access token exchange request.
2082+
*
2083+
* @return ClientResponse The ClientResponse.
2084+
* @throws \Exception
2085+
*/
2086+
public function exchangeRefreshTokenForAccessTokenWithRequest($request)
2087+
{
2088+
$post_data = array(
2089+
'client_id' => $request->client_id
2090+
,'client_secret' => $request->client_secret
2091+
,'grant_type' => $request->grant_type
2092+
,'refresh_token' => $request->refresh_token
2093+
,'scope' => $request->scope
2094+
,'tenantId' => ($request->tenantId !== null ? (string)$request->tenantId : null)
2095+
,'user_code' => $request->user_code
2096+
);
2097+
return $this->startAnonymous()->uri("/oauth2/token")
2098+
->bodyHandler(new FormDataBodyHandler($post_data))
2099+
->post()
2100+
->go();
2101+
}
2102+
19352103
/**
19362104
* Exchange a refresh token for a new JWT.
19372105
*
@@ -1980,6 +2148,33 @@ public function exchangeUserCredentialsForAccessToken($username, $password, $cli
19802148
->go();
19812149
}
19822150

2151+
/**
2152+
* Exchange User Credentials for a Token.
2153+
* If you will be using the Resource Owner Password Credential Grant, you will make a request to the Token endpoint to exchange the user’s email and password for an access token.
2154+
*
2155+
* @param array $request The user credentials access token exchange request.
2156+
*
2157+
* @return ClientResponse The ClientResponse.
2158+
* @throws \Exception
2159+
*/
2160+
public function exchangeUserCredentialsForAccessTokenWithRequest($request)
2161+
{
2162+
$post_data = array(
2163+
'client_id' => $request->client_id
2164+
,'client_secret' => $request->client_secret
2165+
,'grant_type' => $request->grant_type
2166+
,'password' => $request->password
2167+
,'scope' => $request->scope
2168+
,'tenantId' => $request->tenantId
2169+
,'user_code' => $request->user_code
2170+
,'username' => $request->username
2171+
);
2172+
return $this->startAnonymous()->uri("/oauth2/token")
2173+
->bodyHandler(new FormDataBodyHandler($post_data))
2174+
->post()
2175+
->go();
2176+
}
2177+
19832178
/**
19842179
* Begins the forgot password sequence, which kicks off an email to the user so that they can reset their password.
19852180
*
@@ -2221,6 +2416,27 @@ public function introspectAccessToken($client_id, $token)
22212416
->go();
22222417
}
22232418

2419+
/**
2420+
* Inspect an access token issued as the result of the User based grant such as the Authorization Code Grant, Implicit Grant, the User Credentials Grant or the Refresh Grant.
2421+
*
2422+
* @param array $request The access token introspection request.
2423+
*
2424+
* @return ClientResponse The ClientResponse.
2425+
* @throws \Exception
2426+
*/
2427+
public function introspectAccessTokenWithRequest($request)
2428+
{
2429+
$post_data = array(
2430+
'client_id' => $request->client_id
2431+
,'tenantId' => $request->tenantId
2432+
,'token' => $request->token
2433+
);
2434+
return $this->startAnonymous()->uri("/oauth2/introspect")
2435+
->bodyHandler(new FormDataBodyHandler($post_data))
2436+
->post()
2437+
->go();
2438+
}
2439+
22242440
/**
22252441
* Inspect an access token issued as the result of the Client Credentials Grant.
22262442
*
@@ -2240,6 +2456,26 @@ public function introspectClientCredentialsAccessToken($token)
22402456
->go();
22412457
}
22422458

2459+
/**
2460+
* Inspect an access token issued as the result of the Client Credentials Grant.
2461+
*
2462+
* @param array $request The client credentials access token.
2463+
*
2464+
* @return ClientResponse The ClientResponse.
2465+
* @throws \Exception
2466+
*/
2467+
public function introspectClientCredentialsAccessTokenWithRequest($request)
2468+
{
2469+
$post_data = array(
2470+
'tenantId' => $request->tenantId
2471+
,'token' => $request->token
2472+
);
2473+
return $this->startAnonymous()->uri("/oauth2/introspect")
2474+
->bodyHandler(new FormDataBodyHandler($post_data))
2475+
->post()
2476+
->go();
2477+
}
2478+
22432479
/**
22442480
* Issue a new access token (JWT) for the requested Application after ensuring the provided JWT is valid. A valid
22452481
* access token is properly signed and not expired.
@@ -4682,6 +4918,54 @@ public function retrieveUserCodeUsingAPIKey($user_code)
46824918
->go();
46834919
}
46844920

4921+
/**
4922+
* Retrieve a user_code that is part of an in-progress Device Authorization Grant.
4923+
*
4924+
* This API is useful if you want to build your own login workflow to complete a device grant.
4925+
*
4926+
* This request will require an API key.
4927+
*
4928+
* @param array $request The user code retrieval request including optional tenantId.
4929+
*
4930+
* @return ClientResponse The ClientResponse.
4931+
* @throws \Exception
4932+
*/
4933+
public function retrieveUserCodeUsingAPIKeyWithRequest($request)
4934+
{
4935+
$post_data = array(
4936+
'tenantId' => ($request->tenantId !== null ? (string)$request->tenantId : null)
4937+
,'user_code' => $request->user_code
4938+
);
4939+
return $this->startAnonymous()->uri("/oauth2/device/user-code")
4940+
->bodyHandler(new FormDataBodyHandler($post_data))
4941+
->post()
4942+
->go();
4943+
}
4944+
4945+
/**
4946+
* Retrieve a user_code that is part of an in-progress Device Authorization Grant.
4947+
*
4948+
* This API is useful if you want to build your own login workflow to complete a device grant.
4949+
*
4950+
* @param array $request The user code retrieval request.
4951+
*
4952+
* @return ClientResponse The ClientResponse.
4953+
* @throws \Exception
4954+
*/
4955+
public function retrieveUserCodeWithRequest($request)
4956+
{
4957+
$post_data = array(
4958+
'client_id' => $request->client_id
4959+
,'client_secret' => $request->client_secret
4960+
,'tenantId' => ($request->tenantId !== null ? (string)$request->tenantId : null)
4961+
,'user_code' => $request->user_code
4962+
);
4963+
return $this->startAnonymous()->uri("/oauth2/device/user-code")
4964+
->bodyHandler(new FormDataBodyHandler($post_data))
4965+
->post()
4966+
->go();
4967+
}
4968+
46854969
/**
46864970
* Retrieves all the comments for the user with the given Id.
46874971
*
@@ -6415,6 +6699,25 @@ public function validateDevice($user_code, $client_id)
64156699
->go();
64166700
}
64176701

6702+
/**
6703+
* Validates the end-user provided user_code from the user-interaction of the Device Authorization Grant.
6704+
* If you build your own activation form you should validate the user provided code prior to beginning the Authorization grant.
6705+
*
6706+
* @param array $request The device validation request.
6707+
*
6708+
* @return ClientResponse The ClientResponse.
6709+
* @throws \Exception
6710+
*/
6711+
public function validateDeviceWithRequest($request)
6712+
{
6713+
return $this->startAnonymous()->uri("/oauth2/device/validate")
6714+
->urlParameter("client_id", $request->client_id)
6715+
->urlParameter("tenantId", $request->tenantId !== null ? (string)$request->tenantId : null)
6716+
->urlParameter("user_code", $request->user_code)
6717+
->get()
6718+
->go();
6719+
}
6720+
64186721
/**
64196722
* Validates the provided JWT (encoded JWT string) to ensure the token is valid. A valid access token is properly
64206723
* signed and not expired.

0 commit comments

Comments
 (0)