2016-06-30 13:45:29 +02:00
|
|
|
# General OAuth2-Client
|
|
|
|
|
|
|
|
To use this general OAuth2 client-class, include it with
|
2016-07-01 11:31:08 +02:00
|
|
|
<<<<<<< HEAD
|
2016-06-30 15:06:39 +02:00
|
|
|
```
|
2016-07-01 11:31:08 +02:00
|
|
|
require_once('OAuth2Client.php');
|
2016-07-01 11:27:45 +02:00
|
|
|
$oauth2 = new OAuth2([
|
|
|
|
"client_id" => $client_id,
|
|
|
|
"client_secret" => $client_secret,
|
|
|
|
"redirect_uri" => $redirect_uri,
|
|
|
|
"auth" => $auth,
|
|
|
|
"token" => $token,
|
|
|
|
"authorization_type" => $authorization_type,
|
|
|
|
"session" => $session,
|
|
|
|
"verify" => $verify,
|
|
|
|
"grant_type" => $grant_type,
|
|
|
|
"response_type" => $response_type
|
|
|
|
]);
|
2016-06-30 13:45:29 +02:00
|
|
|
```
|
|
|
|
|
2016-07-01 11:31:08 +02:00
|
|
|
```(string) $client_id``` is client id of the OAuth2 application
|
|
|
|
```(string) $client_secret``` is client secret of the OAuth2 application
|
|
|
|
```(string) $redirect_uri``` is the specified redirect-uri for the OAuth2 application
|
|
|
|
```(string) $auth``` is the full url for authorization
|
|
|
|
```(string) $token``` is the full token url
|
2016-06-30 13:45:29 +02:00
|
|
|
|
|
|
|
Optional -
|
|
|
|
|
2016-07-01 11:31:08 +02:00
|
|
|
<<<<<<< HEAD
|
|
|
|
```(string) $authorization_type``` defaults to Bearer
|
|
|
|
```(boolean) $session``` specifies whether the state is to be saved in _SESSION storage, defaults to false
|
|
|
|
```(boolean) $verify``` is whether to verify SSL of host and peer, defaults to true
|
|
|
|
```(string) $grant_type``` defaults to 'authorization_code'
|
|
|
|
```(string) $response_type``` defaults to 'code'
|
2016-06-30 13:45:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
To start the redirect phase
|
|
|
|
|
2016-07-01 11:31:08 +02:00
|
|
|
```$oauth2->redirect($state);```
|
2016-06-30 13:45:29 +02:00
|
|
|
|
|
|
|
($state defaults to false)
|
|
|
|
|
|
|
|
|
|
|
|
To get access token
|
|
|
|
|
2016-07-01 11:31:08 +02:00
|
|
|
```$oauth2->get_access_token();```
|
2016-06-30 13:45:29 +02:00
|
|
|
|
|
|
|
returns the access_token.
|
|
|
|
|
|
|
|
(Optional value is $state, to check up against _SESSION variables)
|
|
|
|
|
|
|
|
|
|
|
|
To get identity
|
|
|
|
|
2016-07-01 11:31:08 +02:00
|
|
|
```$oauth->get_identity($access_token, $user_url);```
|
2016-07-01 11:27:45 +02:00
|
|
|
|
2016-07-01 11:31:08 +02:00
|
|
|
```(string) $user_url``` is the endpoint for fetching info, example: https://auth.dataporten.no/userinfo
|
2016-06-30 13:45:29 +02:00
|
|
|
|
|
|
|
returns the identity-object as returned from the OAuth2-provider.
|
|
|
|
|