Skip to content
This repository has been archived by the owner on Dec 20, 2019. It is now read-only.

TankerHQ/user-token-cs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build

User Token

User token generation in C# for the Tanker SDK.

Installation

You can install it from NuGet.

Usage

using Tanker.UserToken

namespace App
{
    public class TokenManager
    {

        private string RetrieveUserToken(string userId)
        {
            //Fetch a previously stored token
            ...
        }

        private void StoreUserToken(string userId, string token)
        {
            //Store a previously generated token
            ...
        }


        private bool CheckAuth(string userId)
        {
            // Check the user is authenticated
            ...
        }

        public string ServeUserToken(string userId)
        {
            /* Called during sign/up sign in of your users.
               Send a user token, generated if necessary, but only to authenticated
               users */

            if (!CheckAuth(userId))
            {
                throw new UnauthorizedException();
            }
            string token = RetrieveUserToken(userId);

            if (!token)
            {
                var userToken = new Tanker.UserToken(TrustchainId, TrustchainPrivateKey, userId);
                token = userToken.Serialize();
                StoreUserToken(userId, token);
            }

            return token;
        }
    }
}

Going further

Read more about user tokens in the Tanker guide.

About

User token generation in .Net Framework for the Tanker SDK

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages