Developer forum

Forum » Development » Using webapi token to authenticate in frontend

Using webapi token to authenticate in frontend

Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi,

 

Is there a way to use the webapi token to login the user in the frontend?

 

We have this customer building a new frontend in a different CMS (corporate reasons), but still wants to use DW for the checkout process (potentially some other pages - we have little knowledge about it, just trying to support them). Currently they've been using the webapi to get some data, but they are trying to use a reverse proxy and have some pages be served from Dynamicweb, but obviously "cannot" ask the user to login again.

 

Is there a simple way to do this? Maybe by providing the token as a POST request and using some notification to they login the user?

 

Nuno Aguiar


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply
This post has been marked as an answer

You can get the user object using the token by referencing Dynamicweb.Ecommerce.WebAPI and then get the user from the JwtService

string token = GetTheTokenFromRequestOrSomething();
var principal = JwtService.GetPrincipal(token, out User user);

User is still not logged in.

Then I think you can call User.SetCurrentUser - it is marked as obsolute for DW10, but you should be able to use it.

Alternative you can login using the PwToken - something like this:

var handler = new LogOnHandler(_pageId);
handler.ExtranetLoginToken(user.UserName, LogOnHandler.GetPasswordToken(user.Password));

 

Votes for this answer: 1
 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Nicolai,

 

That's great info thanks. And this will be in DW9 only, so not a problem using that obsolete method. Likely the best solution.

 

 

At least this gives me something to go by, thank you very much.

 

Nuno

 

You must be logged in to post in the forum