Using JWT for authentication in an ionic 3 application

前端 未结 1 2025
孤城傲影
孤城傲影 2021-01-21 11:04

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 tha

相关标签:
1条回答
  • 2021-01-21 11:14

    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]
      }
    })
    ]})
    
    0 讨论(0)
提交回复
热议问题