Skip to content

Commit cfc93cc

Browse files
committed
Add API documentation
1 parent 94af021 commit cfc93cc

File tree

3 files changed

+148
-3
lines changed

3 files changed

+148
-3
lines changed

docs/api.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# API
2+
3+
## Enabling API
4+
5+
To enable API capabilities, in module config file `config/module_oidc.php`, find option
6+
`ModuleConfig::OPTION_API_ENABLED` and set it to `true`.
7+
8+
```php
9+
use SimpleSAML\Module\oidc\ModuleConfig;
10+
11+
ModuleConfig::OPTION_API_ENABLED => true,
12+
```
13+
14+
15+
## API Authentication and Authorization
16+
17+
API access tokens are defined in file `config/module_oidc.php`, under option `ModuleConfig::OPTION_API_TOKENS`.
18+
This option is an associative array, where keys are the API access tokens, and values are arrays of scopes.
19+
20+
```php
21+
use SimpleSAML\Module\oidc\Codebooks\ApiScopesEnum;
22+
use SimpleSAML\Module\oidc\ModuleConfig;
23+
24+
ModuleConfig::OPTION_API_TOKENS => [
25+
'strong-random-token-string' => [
26+
ApiScopesEnum::All,
27+
],
28+
],
29+
```
30+
Scopes determine which endpoints are accessible by the API access token. The following scopes are available:
31+
32+
* `\SimpleSAML\Module\oidc\Codebooks\ApiScopesEnum::All`: Access to all endpoints.
33+
* `\SimpleSAML\Module\oidc\Codebooks\ApiScopesEnum::VciAll`: Access to all VCI-related endpoints
34+
* `\SimpleSAML\Module\oidc\Codebooks\ApiScopesEnum::VciCredentialOffer`: Access to credential offer endpoint.
35+
36+
## API Endpoints
37+
38+
Note that all endpoints will have a path prefix based on the SimpleSAMLphp base path and `oidc` module path.
39+
For example, if you serve SimpleSAMLphp using base URL path `simplesaml/`, the path prefix for each API endpoint
40+
will be
41+
42+
`/simplesaml/module.php/oidc/api/`
43+
44+
Check the SimpleSAMLphp config file `config/config.php`, option `baseurlpath` to find the base URL path of the
45+
SimpleSAMLphp installation.
46+
47+
### Credential Offer
48+
49+
Enables fetching a credential offer as per OpenID4VCI specification.
50+
51+
#### Path
52+
53+
`/api/vci/credential-offer`
54+
55+
#### Method
56+
57+
`POST`
58+
59+
#### Authorization
60+
61+
`Bearer Token`
62+
63+
#### Request
64+
65+
The request is sent as a JSON object in the body with the following parameters:
66+
67+
* __grant_type__ (string, mandatory): Specifies the type of grant (issuance flow) being requested. Allowed values are:
68+
* `urn:ietf:params:oauth:grant-type:pre-authorized_code`: Pre-authorized code grant.
69+
* `authorization_code`: Authorization code grant.
70+
* __credential_configuration_id__ (string, mandatory): The identifier for the credential configuration being requested.
71+
This must correspond to a predefined configuration ID for the VCI Issuer. Check the Credential Issuer Configuration URL
72+
`/.well-known/openid-credential-issuer`, under the `credential_configurations_supported` field.
73+
* __use_tx_code__ (boolean, optional, default being `false`): Indicates whether to use transaction code protection for
74+
pre-authorized code grant.
75+
* __users_email_attribute_name__ (string, optional, no default): The name of the attribute that holds the
76+
user's email address. Used when transaction code protection is enabled to send the transaction code to the user's email
77+
address.
78+
* __authentication_source_id__ (string, optional, no default): The identifier for the SimpleSAMLphp authentication
79+
source, that should be used to determine the user's email address attribute. Used if `users_email_attribute_name` is
80+
not specified, and transaction code protection is enabled.
81+
* __user_attributes__ (object, optional, no default): An object containing various user attributes. Used in
82+
pre-authorized code grant to populate credential data.
83+
84+
#### Response
85+
86+
The response is a JSON object with the `credential_offer_uri` field containing the credential offer URI string value.
87+
88+
#### Sample 1
89+
90+
Request a credential offer to issue a credential with the ID `ResearchAndScholarshipCredentialDcSdJwt` using the
91+
authorization code grant.
92+
93+
Request:
94+
95+
```shell
96+
curl --location 'https://idp.mivanci.incubator.hexaa.eu/ssp/module.php/oidc/api/vci/credential-offer' \
97+
--header 'Content-Type: application/json' \
98+
--header 'Authorization: Bearer ***' \
99+
--data '{
100+
"grant_type": "authorization_code",
101+
"credential_configuration_id": "ResearchAndScholarshipCredentialDcSdJwt"
102+
}'
103+
```
104+
105+
Response:
106+
107+
```json
108+
{
109+
"credential_offer_uri": "openid-credential-offer://?credential_offer={\"credential_issuer\":\"https:\\/\\/idp.mivanci.incubator.hexaa.eu\",\"credential_configuration_ids\":[\"ResearchAndScholarshipCredentialDcSdJwt\"],\"grants\":{\"authorization_code\":{\"issuer_state\":\"30616b68fa26b00c5a6391faffc02e4e4fd9b0023fd6a3aa29ec754e2f5e2871\"}}}"
110+
}
111+
112+
```
113+
114+
#### Sample 2
115+
116+
Request a credential offer to issue a credential with the ID `ResearchAndScholarshipCredentialDcSdJwt` using the
117+
pre-authorized code grant with transaction code protection. The user's email address is retrieved from the attribute
118+
`mail`.
119+
120+
Request:
121+
122+
```shell
123+
curl --location 'https://idp.mivanci.incubator.hexaa.eu/ssp/module.php/oidc/api/vci/credential-offer' \
124+
--header 'Content-Type: application/json' \
125+
--header 'Authorization: Bearer ***' \
126+
--data-raw '{
127+
"grant_type": "urn:ietf:params:oauth:grant-type:pre-authorized_code",
128+
"credential_configuration_id": "ResearchAndScholarshipCredentialDcSdJwt",
129+
"use_tx_code": true,
130+
"users_email_attribute_name": "mail",
131+
"user_attributes": {
132+
"uid": [“testuseruid"],
133+
"mail": ["[email protected]"],
134+
"...": [“..."]
135+
}
136+
}'
137+
```
138+
139+
Response:
140+
141+
```json
142+
{
143+
"credential_offer_uri": "openid-credential-offer://?credential_offer={\"credential_issuer\":\"https:\\/\\/idp.mivanci.incubator.hexaa.eu\",\"credential_configuration_ids\":[\"ResearchAndScholarshipCredentialDcSdJwt\"],\"grants\":{\"urn:ietf:params:oauth:grant-type:pre-authorized_code\":{\"pre-authorized_code\":\"_ffcdf6d86cd564c300346351dce0b4ccb2fde304e2\",\"tx_code\":{\"input_mode\":\"numeric\",\"length\":4,\"description\":\"Please provide the one-time code that was sent to e-mail [email protected]\"}}}}"
144+
}
145+
```

docs/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SimpleSAMLphp OIDC module
2+
3+
* [API](api.md)

src/Controllers/Api/VciCredentialOfferApiController.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
use Symfony\Component\HttpFoundation\Request;
1717
use Symfony\Component\HttpFoundation\Response;
1818

19-
/**
20-
* TODO mivanci Add API documentation.
21-
*/
2219
class VciCredentialOfferApiController
2320
{
2421
/**

0 commit comments

Comments
 (0)