- Authentication asserts who a user is.
- Authorization asserts what they can do.
What is authentication?
Authentication confirms the identity of a user. There are a variety of methods available for confirming a user’s identity, from a knowledge factor like username and password combinations to more secure flows that include possession factors or social logins and Single Sign-On (SSO) providers. Oso Cloud is not an authentication provider, but it does integrate easily with authentication providers.How Oso Cloud uses identities
Oso Cloud assumes that you are an authority for authenticating users and that you store identity data, either in a data store or a hosted service. In Oso Cloud, users are identified by a type and ID. If your application uses universally unique identifiers (UUIDs), a user in Oso Cloud might look likeUser{"70f19088-7e97-4ca9-be0a-4deeaeedb7a7"}
.
For example, this is how you
could tell Oso Cloud that user 70f19...
has the "admin"
role on a
particular organization:
Choosing a user identifier
A good user identifier is:- unique per user
- consistent for the same user over time
- accessible from any service in your system with minimal overhead
- The
sub
property in the response from an authentication service or in a JSON Web Token (JWT). - The
uuid
orid
field on theusers
table in a relational datastore.
Hands-on example
In this example, users can update projects by makingPUT
requests to the
/api/project/[projectId]
endpoint. Here we use the front end framework NextJS,
Oso Cloud for authorization, and Stytch for authentication (though any authentication service
will work).
When a user logs in, Stytch stores a random string as a session token.
You authenticate the user’s identity by validating the session token. The
decoded session object contains a user_id
for the user, which we use to
identify the user to Oso Cloud:
user_id
from the session, we ask Oso Cloud if the user can update
the project:
Do I need to sync all my users to Oso Cloud?
You do not need to sync users to Oso Cloud. Instead, you sync your users’ authorization data like roles and permissions. Oso Cloud uses those roles and attributes to make authorization decisions. Since Oso Cloud is deny by default, if you have not synced any roles for a particular user, those authorization decisions will be denied. For more information on adding facts to Oso Cloud, review the facts section of our documentation.What about scopes?
Some authentication services support scopes for users. Scopes are similar to feature flags or global roles. They provide some data that you can use to determine what a user can see or do. But they can only encode information about the user and not about the resources in your application. For example, a user might have thedelete_repository
scope that allows them to delete any
repository. However if you want to restrict users to only delete
repositories they own, a scope is insufficient.
Scopes might suffice if you only require coarse, global
access control, but they’re an incomplete solution that doesn’t support more
fine grained authorization.