KOSKI Student Status
This page describes a feature that is under development and not yet available in any released Trivore ID version. Endpoint paths, parameter names, and error codes may still change before release. The release notes will mention when the feature becomes available.
Trivore ID can verify whether a user is a student using the KOSKI service maintained by the Finnish National Agency for Education (Opetushallitus, OPH). KOSKI holds the study rights (opiskeluoikeudet) of Finnish learners, and it releases them to a third party only after the user has given their consent.
Trivore ID handles the KOSKI side of the process for your application: it asks for the user's consent, stores the resulting KOSKI access token, fetches the study rights when needed, and returns an interpreted student status to your application. Your application never talks to KOSKI directly, and it never needs KOSKI credentials or client certificates of its own.
The flow is similar to Suomi.fi Authorisations: if the user hasn't given their consent yet, your application redirects the user's browser to a URL provided by Trivore ID, and the user returns to your application with a signed result token.
How it works
The overall process has three parts:
- Student status request. Your application asks Trivore ID for the user's student status. If Trivore ID already has a valid KOSKI access token for the user, it answers right away, and the rest of the steps are skipped. Otherwise it returns a consent URL.
- Consent. Your application redirects the user's browser to the consent URL. Trivore ID sends the user to KOSKI, where the user identifies themselves and gives their consent. Trivore ID stores the access token it receives from KOSKI.
- Retrieval and interpretation. Trivore ID fetches the user's study rights from KOSKI, checks that they belong to the right person, and passes them to an external interpretation service (a rule engine) configured for your deployment. The interpreted student status is returned to your application.
Prerequisites
- The Trivore ID deployment has been approved as a KOSKI OAuth2 partner by OPH, and KOSKI integration has been configured in Trivore ID by an administrator. See Configuration.
- The user has signed in to your application using OpenID Connect, and you have their access token.
- The user has a Finnish personal identity code (henkilötunnus) stored in Trivore ID, which in
practice means they have identified themselves through
Suomi.fi identification. Trivore ID uses
it to verify that the data returned by KOSKI belongs to the signed-in user. Without it the
request fails with the error
personal_identity_code_missing.
Requesting the student status
Request the user's student status with the user's access token:
POST /api/rest/v1/user/{userId}/studentstatus/koski HTTP/1.1
Host: {your-id-server}
Content-Type: application/json
Accept: application/json
Authorization: Bearer <user-access-token>
{
"successRedirectUri": "https://app.example.com/koski/success",
"failureRedirectUri": "https://app.example.com/koski/failure",
"nonce": "406ebf05-a777-4df0-bb01-ce4d558b4cc8",
"maxAge": 86400,
"interactive": true
}
| Parameter | Value |
|---|---|
successRedirectUri | Required when interactive is true. URI where the user is directed after the consent process completes successfully. Query parameter result carries the result token. See Result token. |
failureRedirectUri | Required when interactive is true. URI where the user is directed if they cancel the consent or it fails for another reason. Query parameters error and error_description describe the error. |
nonce | Optional. This exact value is included in the result token. Use it to correlate the request with the response. |
maxAge | Optional. The maximum age, in seconds, of previously retrieved student data that is acceptable as a response. If the stored data is older, it's fetched again from KOSKI. 0 always fetches fresh data from KOSKI. If omitted, the default configured in System Preferences is used. |
interactive | Optional, defaults to true. If true and the user hasn't given their consent, the response contains a consent URL. If false, the request fails with consent_required instead. |
The success and failure redirect URIs must be pre-registered in Trivore ID by an administrator. You can add your own query parameters (or a fragment) to them, and they are preserved when the user is redirected.
Response when consent is required
If the user hasn't given their consent, or the stored KOSKI access token has expired, the response contains a URL where the user gives it:
{
"consentRequired": true,
"consentUrl": "https://{your-id-server}/koski/consent?state=..."
}
Redirect the user's browser to consentUrl. Treat the URL as opaque: its state value is
single-use and short-lived, so don't store or reuse the URL — request a new one instead.
Response when consent has already been given
If Trivore ID already holds a valid KOSKI access token for the user, it retrieves the student
status (from KOSKI or, within maxAge, from previously retrieved data) and returns it directly.
No redirect is needed.
{
"consentRequired": false,
"studentStatus": {
"student": true,
"retrievedAt": "2026-11-30T12:00:00Z",
"details": { }
}
}
The content of details is produced by the interpretation service configured for your
deployment, not by Trivore ID. See Interpretation of study rights.
User experience during consent
After being redirected to the consent URL, the user's browser goes through Trivore ID to KOSKI.
At KOSKI, the user identifies themselves with strong electronic identification (Suomi.fi) and is
shown which data the service is asking for. Once they give their consent, they're returned to
Trivore ID, which retrieves and interprets the study rights, and finally redirects the user to the
successRedirectUri with the result token.
If the user cancels the consent, or anything fails along the way, the user is redirected to the
failureRedirectUri with two query parameters:
error: Machine-readable error code. See Error codes.error_description: Human-readable error message.
Result token
On success, the query parameter result is added to the successRedirectUri. Its value is a JWT
that describes the outcome. Normal JWT validation rules apply: verify the signature using the
keys published by Trivore ID, and check the iss, aud, and exp claims.
Example result token payload:
{
// Token issuer, value is the Trivore ID base URL
"iss": "https://{your-id-server}",
// Issued-at timestamp, in epoch seconds
"iat": 1795960800,
// Token expiration timestamp, in epoch seconds
"exp": 1795961100,
// Audience, always contains the success redirect URI without query parameters
"aud": [
"https://app.example.com/koski/success"
],
// Unique token ID. Use this to prevent replay attacks.
"jti": "1b7c4a52-8b8e-4a43-9a5b-7fa0e4f1e0c2",
// The "nonce" value given in the original request
"nonce": "406ebf05-a777-4df0-bb01-ce4d558b4cc8",
// Token type
"type": "urn:trivore:id:koski:student-status:result",
// True if the consent was given and the student status was retrieved
"success": true,
// ID of the user whose student status was retrieved
"userId": "6aa9239b1b5db46501f1e2bc",
// Interpreted student status, same structure as in the API response
"studentStatus": {
"student": true,
"retrievedAt": "2026-11-30T12:00:00Z",
"details": { }
}
}
After a successful consent, later student status requests return the status directly without a redirect, for as long as the KOSKI access token remains valid.
Revoking the consent
Your application can revoke the user's consent, for example when the user asks to stop sharing their study information with the service:
DELETE /api/rest/v1/user/{userId}/studentstatus/koski HTTP/1.1
Host: {your-id-server}
Authorization: Bearer <user-access-token>
The request can be authenticated in either of two ways:
- With a user's access token, as in the example above. A user can always revoke their own
consent. A user can revoke another user's consent only if they have the permission
ACCOUNT_MODIFY_STUDENT, for example a customer service user. - With Management API client credentials using HTTP Basic
authentication, for example from a back-end or customer service system. The API client needs
the permission
ACCOUNT_MODIFY_STUDENT.
DELETE /api/rest/v1/user/{userId}/studentstatus/koski HTTP/1.1
Host: {your-id-server}
Authorization: Basic <base64(client-id:client-secret)>
Revocation deletes the KOSKI access token stored in Trivore ID and asks the interpretation service to delete the user's student data. Any later student status request requires the user to give their consent again.
Interpretation of study rights
Trivore ID doesn't interpret study rights itself. KOSKI returns detailed study right data (institution, type of education, start and end dates, completions, and so on), and deciding whether that data makes the user a "student" depends on the rules of each service — for example, which types of education qualify, or whether part-time studies count.
This interpretation is the job of an external interpretation service (a rule engine) configured
for your deployment. Trivore ID sends it the user's ID, date of birth, and the study right data
retrieved from KOSKI, and returns the result to your application as studentStatus. Contact your
Trivore ID administrator for the details of the interpretation in use. The API the interpretation
service must implement is described in
Implementing the interpretation service.
Before calling the interpretation service, Trivore ID checks that the personal identity code
returned by KOSKI matches the one stored for the user. If they don't match, the data is discarded
and the request fails with personal_identity_code_mismatch. This protects against a case where
someone else identifies themselves at KOSKI during the consent step.
Error codes
Errors are returned as the error property of the API response body, or as the error query
parameter of the failureRedirectUri.
| Error code | Meaning |
|---|---|
personal_identity_code_missing | The user has no personal identity code stored in Trivore ID. Have the user identify themselves with Suomi.fi first. |
personal_identity_code_mismatch | The data returned by KOSKI belongs to a different person than the signed-in user. |
consent_required | The user hasn't given their consent, and the request was made with interactive set to false. |
consent_cancelled | The user cancelled the consent at KOSKI. |
invalid_redirect_uri | A redirect URI isn't registered in Trivore ID. |
koski_unavailable | KOSKI couldn't be reached, or it returned an unexpected error. |
interpretation_failed | The interpretation service couldn't be reached, or it returned an error. |
Configuration
This section is for Trivore ID administrators.
Registering with OPH
KOSKI releases data only to partners approved by OPH. When applying, OPH asks for technical details of the partner service. For a Trivore ID deployment these include:
- The name of the service, shown to the user when consent is asked (in Finnish, Swedish, and English).
- The OAuth2 scopes needed. The interpretation service needs at least the user's date of birth and study right data, and Trivore ID needs the personal identity code for verification.
- The redirect URI, which is
https://{your-id-server}/rp/koski/callback. If you use several base URLs with this feature, register each of them. - The subject distinguished name of the mutual TLS (mTLS) client certificate Trivore ID uses.
- The IP addresses of the Trivore ID deployment.
- The desired lifetime of the consent (the KOSKI access token). KOSKI doesn't issue refresh tokens, so once the access token expires, the user has to give their consent again.
System Preferences
KOSKI settings are configured in the Management UI under System Preferences. They include the
KOSKI client ID, scopes, mTLS client certificate, the interpretation service connection, the
allowed redirect URIs, and the default maxAge.
Monitoring
The metadata of stored KOSKI access tokens (such as scope and expiration time, but not the token itself) can be viewed in the Management UI. Successful and failed consents are recorded in the event log.
Implementing the interpretation service
This section is for developers who implement the external interpretation service (rule engine) that Trivore ID calls. Trivore ID acts as the client: it calls two HTTP endpoints of the service, one to interpret a user's study rights and one to delete a user's data when the consent is revoked.
General requirements
- The service must be reachable from Trivore ID over HTTPS.
- Request and response bodies are JSON (
application/json, UTF-8). - Trivore ID authenticates to the service with the credentials configured in
System Preferences, sent in the
Authorizationheader. The service must reject requests without valid credentials with401 Unauthorized. - Trivore ID applies the request timeout configured in System Preferences. A request that times out is handled like an error response.
- Both endpoints are addressed relative to the base URL configured in System Preferences, shown
below as
{interpretation-service-url}.
Interpreting study rights
Trivore ID calls this endpoint every time it has retrieved study rights from KOSKI, both right after the consent and on later student status requests that fetch fresh data.
POST {interpretation-service-url}/student-status HTTP/1.1
Content-Type: application/json
Accept: application/json
Authorization: <configured credentials>
{
"requestId": "0f6b8e2c-3d4a-4f1e-9b7a-2c5d8e9f1a3b",
"userId": "6aa9239b1b5db46501f1e2bc",
"birthDate": "2005-02-21",
"retrievedAt": "2026-11-30T12:00:00Z",
"scope": "HENKILOTIEDOT_KAIKKI_TIEDOT OPISKELUOIKEUDET_AKTIIVISET_JA_PAATTYNEET_OPINNOT",
"opiskeluoikeudet": [
{
"oid": "1.2.246.562.15.20709430670",
"oppilaitos": { "oid": "1.2.246.562.10.51720121923" },
"tyyppi": { "koodiarvo": "ammatillinenkoulutus" },
"suoritukset": [ ]
}
]
}
| Field | Value |
|---|---|
requestId | Unique ID of this request. Trivore ID also records it in the event log, so include it in your own logs to correlate the two. |
userId | ID of the Trivore ID user. Use it as the key for any data the service stores about the user. |
birthDate | The user's date of birth, YYYY-MM-DD, as returned by KOSKI. |
retrievedAt | When Trivore ID retrieved the data from KOSKI. |
scope | The scopes of the KOSKI access token, as reported by KOSKI. Because the user can change the requested scope at KOSKI before giving their consent, check that the data was retrieved with the scope your rules expect. |
opiskeluoikeudet | The study rights returned by KOSKI, unmodified. Their structure depends on scope and is defined by the KOSKI OAuth2 data schemas. If KOSKI has no study rights for the user, this is an empty array. |
Trivore ID has already verified that the data belongs to the user before calling the service, so the personal identity code isn't sent.
On success, respond with 200 OK and the interpreted status:
{
"student": true,
"details": {
"studentType": "VOCATIONAL",
"validUntil": "2027-07-31"
}
}
| Field | Value |
|---|---|
student | Required. true if the user is a student according to the service's rules, otherwise false. |
details | Optional. Any JSON object. Trivore ID doesn't interpret it, but passes it unchanged to the application as studentStatus.details. |
An empty opiskeluoikeudet array, or study rights that don't meet the rules, is a normal outcome:
respond with 200 OK and "student": false, not with an error.
Respond with an error status (4xx or 5xx) only if the request can't be processed, for example
because the data is malformed or the scope is not the expected one. Trivore ID then fails the
student status request with the error interpretation_failed, and records the response status
in the event log. The response body of an error is not shown to the application or the user.
Deleting a user's data
Trivore ID calls this endpoint when the user's consent is revoked. The service must delete all data it has stored about the user, including any study right data and interpretation results.
DELETE {interpretation-service-url}/student-status/{userId} HTTP/1.1
Authorization: <configured credentials>
Respond with 204 No Content when the data has been deleted. The endpoint must be idempotent: if
the service has no data about the user, respond with 204 No Content or 404 Not Found, both of
which Trivore ID treats as success.
If the service responds with any other status, or can't be reached, Trivore ID still deletes the
KOSKI access token it stores, records the failure in the event log, and fails the revocation
request with the error interpretation_failed. The application can then retry the revocation.