To implement Opinsys Authentication to an external service, you must receive a shared secret from Opinsys support at tuki @ opinsys.fi
. To receive it, you must provide us the following information:
Once the shared sercret is in place, the external service may redirect the user's web browser to https://api.opinsys.fi/v3/sso
with a return_to
query string key which determines where the user will be redirected back. The hostname of the return_to
URL must match the FQDN provided to us.
Example redirect URL might be:
https://api.opinsys.fi/v3/sso?return_to=http%3A%2F%2Fexample.com
When a user is authenticated he/she will be redirected to the URL specified in the return_to
query string key. The URL is augmented with a jwt
query string key which will contain a JSON Web Token. The external service is expected to decode this token, validate it with the given shared secret and make sure that it is not issued too long a ago or in the future. The token will contain following claims:
iat
Identifies the time at which the JWT was issued as Unix timestamp integerjti
A unique identifier for the JWT stringid
Unique identifier for the user integerusername
stringfirst_name
stringlast_name
stringemail
User email stringprimary_school_id
stringschools
List of schools the user belongs to arrayid
Unique identifier for the school stringname
Human-readable school name stringabbreviation
Valid POSIX name for the school stringschool_code
The Finnish school code. Can be null
if it hasn't been specified. Not all schools have this set. stringroles
One or more (there should always be at least one) roles the user has in this school. An array of stringsteacher
, staff
, student
, visitor
, parent
, admin
, schooladmin
and testuser
groups
List of groups the user has in the school: arrayid
Unique identifier for the group stringname
Human-readable group name stringabbreviation
Valid POSIX name for the group stringtype
Type of the group. stringnull
(if the type is unspecified) or one of these:teaching group
, year class
, administrative group
, course
, archive users
or other groups
learning_materials_charge
stringlearningMaterialsCharge
attribute for this user in this school. Omitted if the value is not known for this school ("best effort"). When specified, it is formatted as X;YYYYY
where X is either 0 or 1, and YYYYY is the school code. More information here (in Finnish).organisation_name
stringorganisation_domain
stringjyvaskyla.opinsys.fi
.learner_id
stringnull
if the ID has not been set.In addition to those above, there are some "extra" fields that can be used, but you should NOT rely on their presence (they might not always exist). They are:
puavo_id
integerid
, but this field gives it an explicit name.external_id
stringnull
for others.preferred_language
stringen
, fi
, sv
, de
and so on) identifying the language this user primarily speaks. Can be used to localize the environment.year_class
stringnull
for non-students and students who are not in a Primus-enabled school.user_type
stringschools
array as described above.By default external services are not activated for all Opinsys organisations. Each organisation or individual schools must activate the external services on their behalf. They can do this directly from their management interface.
If the external service knows in advance from which organisation the user is coming from it can make the login a bit easier by specifying an additional query string key organisation
to the redirect URL:
https://api.opinsys.fi/v3/sso?organisation=kehitys.opinsys.fi&return_to=http%3A%2F%2Fexample.com
Then users don't have to manually type their organisation during login.
When the user is coming from a Opinsys -managed desktop, Kerberos will be used for the authentication. The user will not even see the Opinsys login form in this case. He/she will be directly redirected back to return_to
URL with a jwt
key. The organisation presetting is ignored when Kerberos is active because the organisation will be read from the Kerberos ticket. This is enabled by default for all external services using Opinsys Authentication.
If you need to relay some custom fields through the Authentication service you can just add them to the return_to
URL. Just remember to escape the value.
Example:
https://api.opinsys.fi/v3/sso?return_to=https%3A//example.com/path%3Fcustom_field%3Dbar
Redirects user to:
https://example.com/path?custom_field=bar&jwt=<the jwt token>
Because browsers have length limits for URLs and headers, full school and group information for user can not always be included in JWT-data. In this situation you can fetch the full information using separate API.
If you need to use this API, ask required credentials from tuki @ opinsys.fi
. You need to tell which organisation_domain
users information you want to fetch.
API uses Basic Authentication with username and password.
API is available using the GET
-request from:
https://DOMAIN/v3/users/USERNAME
Substitute DOMAIN
with the users organisation_domain
and USERNAME
with users username.
API returns all available user information as JSON.
Feel free to contact us at dev @ opinsys.fi
or open up an issue on Github if you have any trouble implementing this. If you think this documentation could be improved, contact us.