Save Token to User Machine

Asked

Viewed 428 times

1

I made an integration with the GoogleDrive and by doing all the authorization on the consent screen, it creates a token in the appdata user, however I put this application in Azure in a VM.

Only that by creating this token he’s creating in the appdata of VM, but I would like it to create on the user machine that is accessing the application, follows the code:

UserCredential Credencial = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets 
{ 
   ClientId = ClienteID, 
   ClientSecret = ClienteSenha 
}, 
scopes, NomeUsuario, CancellationToken.None, new FileDataStore("token.aut")).Result;

If anyone can help me solve it I appreciate.

  • You can use HTML5 Storage to store this data, how about?

  • this token can be stored in an encrypted cookie using Asp.net mvc ? or using Localstorage or Session Storage? or use in a variable ?

1 answer

1

//Armazenando o token com localstorage
localStorage.setItem('nomedotoken', token);

//Obtendo token com localstorage
var token = localStorage.getItem("nomedotoken");

//Armazenando o token com sessionStorage
sessionStorage.setItem('chave', 'valor');

//Obtendo token com sessionStorage
var data = sessionStorage.getItem('chave');

sessionStorage allows you to access a Session Storage object. SessionStorage is similar to localStorage, the only difference is that while the data stored in the localStorage does not expire, the data in sessionstorage has its data cleared when expiring the page session

Using Asp.net MVC storing in encrypted cookie

var client = new RestClient("http://localhost:15797");

var request = new RestRequest("api/security/token", Method.POST);
request.AddParameter("grant_type", "password");
request.AddParameter("username", Username);
request.AddParameter("password", Password);

 IRestResponse<TokenViewModel> response = client.Execute<TokenViewModel>(request);
 var token = response.Data.access_token;

 if (!String.IsNullOrEmpty(token))
     FormsAuthentication.SetAuthCookie(token, false);
  • So I tried to do this in the file . Cs but there is no way, missing reference

  • instala restsharp https://www.nuget.org/packages/RestSharp

  • So... but how would I replace the... new Filedatastore("token.aut").... exactly? because there I pass the folder where the token will be saved... in which case it would look like?

  • In this case each request will pass token in the request header a look at this video https://www.youtube.com/watch?v=c4Fden4jptc&t=703s

Browser other questions tagged

You are not signed in. Login or sign up in order to post.