SenseNet / sn-client-dotnet

A .Net client for sensenet that makes it easy to use the REST API of the Content Repository.
https://www.sensenet.com/
GNU General Public License v2.0
7 stars 16 forks source link

Authenticate using an access token #104

Closed tusmester closed 1 year ago

tusmester commented 1 year ago

This story is part of an effort to make the following scenario simpler: the .Net client is used on a backend Asp.Net server to make server-to-server calls to a separate repository service.

There is a use case when a user authenticates in their browser, sends a token to the custom backend app (usually an Asp.Net app) and we need to connect to a separate sensenet repository service using that token - in the name of the authenticated user, not as a technical admin.

In the previous API we already solved this: #70

Now we need to extend the new Repository API with a possibility to provide an access token and execute requests in the name of the user represented by the token.

Proposal

Extend the RepositoryCollection API with a new overload of the GetRepositoryAsync method that takes a token (or an AuthenticationInfo) parameter:

public async Task<IRepository> GetRepositoryAsync(string name, AuthenticationInfo authInfo, CancellationToken cancel)

This method would load a repository instance constructed specifically for the provided token or api key. This would mean multiple IRepository instances cached for the same sensenet repository but for different users. The cache key currently is the provided name but we could construct a cache key that also includes the api key or the token. The underlying server API already supports providing an access token, no need to rewrite anything.