How can i generate token to identity user and also controll the session

Dear All I am creating a dash app where i want to generate a token for webpage and controll the session.

Also Help me with a code that once user clicks Logout button then his tab or chrome or ie closes.

REgards
Rahul