Skip to content

Commit

Permalink
Merge pull request #141 from auth0/4.x.x-dev
Browse files Browse the repository at this point in the history
Release 4.0.12
  • Loading branch information
glena authored Feb 21, 2017
2 parents f39ccd3 + 1f84c52 commit f5960df
Show file tree
Hide file tree
Showing 32 changed files with 866 additions and 20 deletions.
152 changes: 152 additions & 0 deletions src/API/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,38 @@

class Authentication {

/**
* @var string
*/
private $client_id;

/**
* @var string
*/
private $client_secret;

/**
* @var string
*/
private $domain;

/**
* @var ApiClient
*/
private $apiClient;

/**
* @var array
*/
private $guzzleOptions;

/**
* Authentication constructor.
* @param string $domain
* @param string|null $client_id
* @param string|null $client_secret
* @param array $guzzleOptions
*/
public function __construct($domain, $client_id = null, $client_secret = null, $guzzleOptions = []) {

$this->client_id = $client_id;
Expand Down Expand Up @@ -42,6 +68,13 @@ protected function setApiClient() {
$this->apiClient = $client;
}

/**
* @param string $client_secret
* @param string $redirect_uri
* @param array $extra_params
* @return Oauth2Client
* @throws ApiException
*/
public function get_oauth_client($client_secret, $redirect_uri, $extra_params = []) {

if (empty($this->client_id)) {
Expand All @@ -56,6 +89,14 @@ public function get_oauth_client($client_secret, $redirect_uri, $extra_params =
return new Oauth2Client($extra_params);
}

/**
* @param string $response_type
* @param string $redirect_uri
* @param null|string $connection
* @param null|string $state
* @param array $aditional_params
* @return string
*/
public function get_authorize_link($response_type, $redirect_uri, $connection = null, $state = null, $aditional_params = []) {

$aditional_params['response_type'] = $response_type;
Expand All @@ -75,30 +116,51 @@ public function get_authorize_link($response_type, $redirect_uri, $connection =
return "https://{$this->domain}/authorize?$query_string";
}

/**
* @param string $client_id
* @param string $connection
* @return string
*/
public function get_samlp_link($client_id, $connection = '') {

return "https://{$this->domain}/samlp/$client_id?connection=$connection";

}

/**
* @param string $client_id
* @return string
*/
public function get_samlp_metadata_link($client_id) {

return "https://{$this->domain}/samlp/metadata/$client_id";

}

/**
* @param string $client_id
* @return string
*/
public function get_wsfed_link($client_id) {

return "https://{$this->domain}/wsfed/$client_id";

}

/**
* @return string
*/
public function get_wsfed_metadata_link() {

return "https://{$this->domain}/wsfed/FederationMetadata/2007-06/FederationMetadata.xml";

}

/**
* @param null|string $returnTo
* @param null|string $client_id
* @return string
*/
public function get_logout_link($returnTo = null, $client_id = null) {

$params = [];
Expand All @@ -114,6 +176,13 @@ public function get_logout_link($returnTo = null, $client_id = null) {
return "https://{$this->domain}/v2/logout?$query_string";
}

/**
* @param string $access_token
* @param string $connection
* @param string $scope
* @param array $aditional_params
* @return mixed
*/
public function authorize_with_accesstoken($access_token, $connection, $scope = 'openid', $aditional_params = []){

$data = array_merge($aditional_params, [
Expand All @@ -131,6 +200,16 @@ public function authorize_with_accesstoken($access_token, $connection, $scope =
->call();
}

/**
* @param string $username
* @param string $password
* @param string $scope
* @param null|string $connection
* @param null|string $id_token
* @param null|string $device
* @return mixed
* @throws ApiException
*/
public function authorize_with_ro($username, $password, $scope = 'openid', $connection = null, $id_token = null, $device = null){

$data = [
Expand Down Expand Up @@ -163,6 +242,12 @@ public function authorize_with_ro($username, $password, $scope = 'openid', $conn
->call();
}

/**
* @param string $email
* @param string $type
* @param array $authParams
* @return mixed
*/
public function email_passwordless_start($email, $type, $authParams = []){

$data = [
Expand All @@ -184,6 +269,10 @@ public function email_passwordless_start($email, $type, $authParams = []){
->call();
}

/**
* @param string $phone_number
* @return mixed
*/
public function sms_passwordless_start($phone_number){

$data = [
Expand All @@ -200,18 +289,34 @@ public function sms_passwordless_start($phone_number){
->call();
}

/**
* @param string $phone_number
* @param string $code
* @param string $scope
* @return mixed
*/
public function sms_code_passwordless_verify($phone_number, $code, $scope = 'openid'){

return $this->authorize_with_ro($phone_number, $code, $scope, 'sms');

}

/**
* @param string $email
* @param string $code
* @param string $scope
* @return mixed
*/
public function email_code_passwordless_verify($email, $code, $scope = 'openid'){

return $this->authorize_with_ro($email, $code, $scope, 'email');

}

/**
* @param string$access_token
* @return mixed
*/
public function userinfo($access_token){

return $this->apiClient->get()
Expand All @@ -222,6 +327,10 @@ public function userinfo($access_token){

}

/**
* @param string $id_token
* @return mixed
*/
public function tokeninfo($id_token){

return $this->apiClient->get()
Expand All @@ -234,6 +343,17 @@ public function tokeninfo($id_token){

}

/**
* @param string $id_token
* @param string $type
* @param string $target_client_id
* @param string $api_type
* @param array $aditional_params
* @param string $scope
* @param string $grant_type
* @return mixed
* @throws ApiException
*/
public function delegation($id_token, $type, $target_client_id, $api_type, $aditional_params = [], $scope = 'openid', $grant_type = 'urn:ietf:params:oauth:grant-type:jwt-bearer'){

if (! in_array($type, ['id_token', 'refresh_token'])) {
Expand All @@ -257,10 +377,21 @@ public function delegation($id_token, $type, $target_client_id, $api_type, $adit

}

/**
* @return string
*/
public function get_access_token() {
return $this->access_token;
}

/**
* @param string $user_id
* @param string $protocol
* @param string $impersonator_id
* @param string $client_id
* @param array $additionalParameters
* @return mixed
*/
public function impersonate($user_id, $protocol, $impersonator_id, $client_id, $additionalParameters=[]){

$data = [
Expand All @@ -280,6 +411,15 @@ public function impersonate($user_id, $protocol, $impersonator_id, $client_id, $

}

/**
* @param string$client_id
* @param string$client_secret
* @param string $grant_type
* @param null|string $code
* @param null|string $audience
* @param null|string $scope
* @return mixed
*/
public function oauth_token($client_id, $client_secret, $grant_type = 'client_credentials', $code = null, $audience = null, $scope = null) {

$data = [
Expand Down Expand Up @@ -308,6 +448,12 @@ public function oauth_token($client_id, $client_secret, $grant_type = 'client_cr
->call();
}

/**
* @param string $email
* @param string $password
* @param string $connection
* @return mixed
*/
public function dbconnections_signup($email, $password, $connection) {

$data = [
Expand All @@ -325,6 +471,12 @@ public function dbconnections_signup($email, $password, $connection) {
->call();
}

/**
* @param string $email
* @param string $connection
* @param null|string $password
* @return mixed
*/
public function dbconnections_change_password($email, $connection, $password = null) {

$data = [
Expand Down
4 changes: 4 additions & 0 deletions src/API/Header/Authorization/AuthorizationBearer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

class AuthorizationBearer extends Header {

/**
* AuthorizationBearer constructor.
* @param string $token
*/
public function __construct ($token) {
parent::__construct("Authorization", "Bearer $token");
}
Expand Down
4 changes: 4 additions & 0 deletions src/API/Header/ContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

class ContentType extends Header {

/**
* ContentType constructor.
* @param string $contentType
*/
public function __construct ($contentType) {
parent::__construct("Content-Type", $contentType);
}
Expand Down
21 changes: 21 additions & 0 deletions src/API/Header/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,43 @@

class Header {

/**
* @var string
*/
protected $header;

/**
* @var string
*/
protected $value;

/**
* Header constructor.
* @param string $header
* @param string $value
*/
public function __construct($header, $value) {
$this->header = $header;
$this->value = $value;
}

/**
* @return string
*/
public function getHeader() {
return $this->header;
}

/**
* @return string
*/
public function getValue() {
return $this->value;
}

/**
* @return string
*/
public function get() {
return "{$this->header}: {$this->value}\n";
}
Expand Down
Loading

0 comments on commit f5960df

Please sign in to comment.