You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not attached token to request:
"his library does not have any functionality for (or opinion about) implementing user authentication and retrieving JWTs to begin with. Those details will vary depending on your setup, but in most cases, you will use a regular HTTP request to authenticate your users and then save their JWTs in local storage or in a cookie if successful."
code example: request to api in django localhost,
return this.http.post(http://localhost:8000/wells/api/v1/get_all_wells_by_user/, {},options)
result: response http 401
app.module.ts:
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {RouteReuseStrategy} from '@angular/router';
import {IonicModule, IonicRouteStrategy} from '@ionic/angular';
import {AppComponent} from './app.component';
import {AppRoutingModule} from './app-routing.module';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {HttpClientModule, HTTP_INTERCEPTORS} from "@angular/common/http";
import {JwtModule, JwtInterceptor, JWT_OPTIONS} from "@auth0/angular-jwt";
export function tokenGetter() {
return localStorage.getItem("access_token");
}
Description
Not attached token to request:
"his library does not have any functionality for (or opinion about) implementing user authentication and retrieving JWTs to begin with. Those details will vary depending on your setup, but in most cases, you will use a regular HTTP request to authenticate your users and then save their JWTs in local storage or in a cookie if successful."
code example: request to api in django localhost,
return this.http.post(
http://localhost:8000/wells/api/v1/get_all_wells_by_user/
, {},options)result: response http 401
app.module.ts:
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {RouteReuseStrategy} from '@angular/router';
import {IonicModule, IonicRouteStrategy} from '@ionic/angular';
import {AppComponent} from './app.component';
import {AppRoutingModule} from './app-routing.module';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {HttpClientModule, HTTP_INTERCEPTORS} from "@angular/common/http";
import {JwtModule, JwtInterceptor, JWT_OPTIONS} from "@auth0/angular-jwt";
export function tokenGetter() {
return localStorage.getItem("access_token");
}
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
IonicModule.forRoot(),
AppRoutingModule,
BrowserAnimationsModule,
JwtModule.forRoot({
config: {
tokenGetter: tokenGetter,
allowedDomains: ["http://localhost:8000/*"],
disallowedRoutes: ["http://example.com/examplebadroute/"],
},
}),
HttpClientModule
],
providers: [
{provide: RouteReuseStrategy, useClass: IonicRouteStrategy},
{provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true},
],
bootstrap: [
AppComponent
],
})
export class AppModule {
}
Environment
Framework and more data:
FRONTEND
Ionic:
Ionic CLI : 6.20.8
Ionic Framework : @ionic/angular 6.5.1
@angular-devkit/build-angular : 15.1.3
@angular-devkit/schematics : 15.1.3
@angular/cli : 15.1.3
@ionic/angular-toolkit : 6.1.0
Capacitor:
Capacitor CLI : 4.6.2
@capacitor/android : not installed
@capacitor/core : 4.6.2
@capacitor/ios : not installed
Utility:
cordova-res : not installed globally
native-run : 1.7.1
System:
NodeJS : v19.5.0
npm : 9.4.0
OS : Linux 5.15
BACKEND
Django 3.2.16
Configurations - settings
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
#'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
'rest_framework_simplejwt.authentication.JWTTokenUserAuthentication',
#'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
),
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
}
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(days=1),
'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
}
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework_jwt',
'rest_framework',
'rest_framework.authtoken',
'ohm2_handlers_light',
'corsheaders'
]
@api_view(['POST'])
#@requires_scope('wells:get_all_wells_by_user')
#@authentication_classes((TokenAuthentication,))
@permission_classes((IsAuthenticated,))
def get_all_wells_by_user(request):
print(request)
#print(request.headers)
res, error = dispatcher.get_all_wells_by_user(request, request.data)
if error:
return JsonResponse({"error": error.regroup()})
return JsonResponse(res)
The text was updated successfully, but these errors were encountered: