0

We have a REST application which uses BASIC authentication and users for our application are configured in tomcat-users.xml. We wanted to develop Angular web UI which make use of REST application as backend. How can we implement login and logout mechanism for angular UI As REST is stateless how can we achieve this?

As part of my analysis I have explored JWT authentication mechanism with which we cannot achieve proper Logout mechanism apart of removing the token from client.

Could someone share some ideas to workout this integration to implement proper Login and Logout mechanism.

Rocks
  • 1

1 Answers1

0

Using io.jsonwebtoken:

Strin token = Jwts.builder().setSubject(username).claim(template.typeKey(), template.type())
    .setExpiration(new Date(validity)).signWith(SignatureAlgorithm.HS512, template.secret()).compact();

TokenTemplate interface:

public interface TokenTemplate {

    byte[] secret();

    long validity();

    String typeKey();

    String type();
}

I then have both authentication and normal token. Authentication token have a lot shorter duration that refresh token, and refresh token can be used to attain new authentication tokens. Works very well:)

Binary Igor
  • 168
  • 1
  • 5
  • Thanks for your input!! I have a question related to token expiry when the user is active and using the angular application.Could you please share how to handle the use case. – Rocks Dec 04 '18 at 04:24