paulhobbel / angular2-auth

Provides an angular2 auth module to handle authentication based on JWT
MIT License
13 stars 10 forks source link

Documentate #3

Open paulhobbel opened 8 years ago

paulhobbel commented 8 years ago

Make a doc for this library so people know how to use it. Atleast show how to set it up...

nimatrazmjo commented 7 years ago

Please provide a documentation. I am using it, but I dont know how to used it. I am stacked on a part where in loggedIn() function and it gives me this error

A JWT Token must have 3 parts!

The server which I am using is Loopback framework and it returns it own Token. the loopback token looks like this

Ff5qyulO193bGy7f90USTUT8J2Mwce8YfalDFbhDjwa99zK3Ukx2YGnSIIfDOGjB

paulhobbel commented 7 years ago

Yea I need to work on the documentation, this module currently only works with jwt tokens. Could you tell me a little bit more about Loopback?

nimatrazmjo commented 7 years ago

Loopback is a Node.js API framework which is build base and expressjs framework.loopback.io. The documentation for authentication is : user login.

By default loopback return Ff5qyulO193bGy7f90USTUT8J2Mwce8YfalDFbhDjwa99zK3Ukx2YGnSIIfDOGjB , but what I did is that added express-jwt to loopback and return a JWT token.

Also, isExpired() function does not work correctly, it take 1970-01-01 00:00:00 + timeout

paulhobbel commented 7 years ago

Oh that shouldn't happen, will take a look into that later today

paulhobbel commented 7 years ago

Are you sure the exp key in your token is set correctly

nimatrazmjo commented 7 years ago

Yes, I think I found the problem. There is problem with getExpirationDate function. inside of this function you have let date = new Date(0); which returns 1970-01-01T00:00:00.000Z.

I think its wrong. It should get iat property of JWT which is issue at.

The function should look like

public getExpirationDate(): any { let decoded = this.decodeToken(); if(!decoded.hasOwnProperty('exp') && !decoded.hasOwnProperty('iat')) { return new Date(); } let issueAt = decoded.iat let date = new Date(issueAt*1000); date.setUTCSeconds(decoded.exp); return date; }

paulhobbel commented 7 years ago

Oh yea, indeed can you make a pull request

nimatrazmjo commented 7 years ago

I will

paulhobbel commented 7 years ago

@nimatullah actually my way was correct. The exp is a timestamp, this starts counting from 1970-01-01T00:00:00.000Z. My way is a bit weird indeed, but it does work