Using JWT for authentication in an ionic 3 application

為{幸葍}努か 提交于 2019-12-20 03:10:05

问题


I have an ionic 3 application where I want to use the touchId feature.

The backend API is being developed in .net.

For my authentication model, I'm thinking that after a user enters a login name and password and is authenticated by the server, it sends back a JWT token.

I can store the token locally and then every time a user uses the touchId it checks if a token is stored locally, then matches that token to the server and that will allow access.

Is this how it works?


回答1:


you can use angular2-jwt, it works perfectly and send your token automatically with all your http requests and you can manage your token expiration very easy

you can only give the source of your access token in your config file from ionic storage, here is the config for ionic:

import { JwtModule, JWT_OPTIONS } from '@auth0/angular-jwt';
import { Storage } from '@ionic/storage';

export function jwtOptionsFactory(storage) {
return {
  tokenGetter: () => {
   return storage.get('access_token');
 }
}
}


@NgModule({

imports: [
 JwtModule.forRoot({
    jwtOptionsProvider: {
    provide: JWT_OPTIONS,
    useFactory: jwtOptionsFactory,
    deps: [Storage]
  }
})
]})


来源:https://stackoverflow.com/questions/49559398/using-jwt-for-authentication-in-an-ionic-3-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!