Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add application credential authentication type #354

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .phpunit.result.cache
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file should be removed

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/Identity/v3/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -837,4 +837,17 @@ public function deletePolicy(): array
'params' => ['id' => $this->params->idUrl('policy')],
];
}

public function postApplicationCredentialsTokens(): array
{
return [
'method' => 'POST',
'path' => 'auth/tokens',
'params' => [
'methods' => $this->params->methods(),
'application_credential' => $this->params->applicationCredential(),
'tokenId' => $this->params->tokenBody(),
],
];
}
}
11 changes: 8 additions & 3 deletions src/Identity/v3/Models/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,20 @@ public function create(array $data): Creatable
if (!isset($data['user']['id']) && empty($data['user']['domain'])) {
throw new \InvalidArgumentException('When authenticating with a username, you must also provide either the domain name or domain ID to '.'which the user belongs to. Alternatively, if you provide a user ID instead, you do not need to '.'provide domain information.');
}
} elseif (isset($data['tokenId'])) {
} elseif (isset($data['application_credential'])) {
$data['methods'] = ['application_credential'];
if (!isset($data['application_credential']['id']) && empty($data['application_credential']['secret'])) {
throw new \InvalidArgumentException('To authenticate with an application credential, specify “application_credential” as the auth method. The ID of the application credential used for authentication. The secret for authenticating the application credential.');
}
} elseif (isset($data['tokenId'])) {
$data['methods'] = ['token'];
} else {
throw new \InvalidArgumentException('Either a user or token must be provided.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error is not valid anymore. Add application_credentials there.

}

$response = $this->execute($this->api->postTokens(), $data);
$definition = (isset($data['user']) || isset($data['tokenId'])) ? $this->api->postTokens() : $this->api->postApplicationCredentialsTokens();
$response = $this->execute($definition, $data);
$token = $this->populateFromResponse($response);

// Cache response as an array to export if needed.
// Added key `id` which is auth token from HTTP header X-Subject-Token
$this->cachedToken = Utils::flattenJson(Utils::jsonDecode($response), $this->resourceKey);
Expand Down
18 changes: 18 additions & 0 deletions src/Identity/v3/Params.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,22 @@ public function blob(): array
'description' => "This does something, but it's not explained in the docs (as of writing this)",
];
}

public function applicationCredential(): array
{
return [
'type' => self::OBJECT_TYPE,
'path' => 'auth.identity',
'properties' => [
'id' => [
'type' => self::STRING_TYPE,
'description' => 'The ID of the application credential used for authentication. If not provided, the application credential must be identified by its name and its owning user.',
],
'secret' => [
'type' => self::STRING_TYPE,
'description' => 'The secret for authenticating the application credential.',
],
],
];
}
}
Loading