I have django app that is using postgresql as a backend. It have different authentication method and this app running on server A .
setting.py:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'login',
'reports',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'reporting.urls'
TEMPLATE_PATH = os.path.join(BASE_DIR, 'templates')
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_PATH],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'reporting.wsgi.application'
and my second application is on Nodejs with backend mongoDB and authentication method is passport-local. It is running on server B
primary app is Django.
Now I want If Login from django app and click to link that directly go to Nodejs app without login.
Or any other method for login in both application with single authentication.
Related
I just deployed my website on Heroku, an integral part of the functionality of the site is to receive post requests from another website of mine. I'm using DRF's TokenAuthentication for my authentication. In my local environment everything works perfectly, but the same cannot be said for the live website. Whenever I send a POST request I receive a 401 error, the new token is added to the request's header and the data is exactly the same as the data used in the local environment. Any help would be gladly appreciated.
views.py
class PetCreateView(CreateAPIView):
serializer_class = PetSerializer
permission_classes = [IsAuthenticated, ]
def perform_create(self, serializer):
if Breed.objects.filter(user_id=self.request.POST.get('breed_name', None)).exists():
pass
else:
Breed.objects.create( breed_name=self.request.POST.get('breed_name', None),
size=self.request.POST.get('size', None),
temperament=self.request.POST.get('temperament', None),
energy=self.request.POST.get('energy', None),
hypoallergenic=self.request.POST.get('hypoallergenic', None))
breed = Breed.objects.get(breed_name=self.request.POST.get('breed_name', None))
# Assigns a groomer the created Pet
groomer = assign_groomer(breed)
serializer.save(groomer=groomer, breed=breed)
SpaReport.objects.create(breed=breed, groomer=groomer)
settings.py
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'bootstrap3',
'captcha',
'django_celery_beat',
'django_celery_results',
'mathfilters',
'storages',
'account',
'sales',
'scrty',
'analytics'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'pettracker.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR, ],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'scrty.context_processors.from_settings',
],
},
},
]
WSGI_APPLICATION = 'pettracker.wsgi.application'
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.TokenAuthentication',
],
}
Well I am trying to add login and sign up with facebook functionality and when i click on login with facebook it takes me to facebook but shows an error such as
Facebook has detected Believer isn't using a secure connection to transfer information.
Until Believer updates its security settings, you won't be able to use Facebook to log into it.
I used comments for those lines which i add for social app. This code is from my project/settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'bootstrap3',
'accounts',
'social_django', # <--adding social app
]
AUTHENTICATION_BACKENDS = (
'social_core.backends.facebook.FacebookOAuth2',
'social_core.backends.twitter.TwitterOAuth',
'social_core.backends.github.GithubOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'social_django.middleware.SocialAuthExceptionMiddleware', #<--for social app
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR,],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'social_django.context_processors.backends', # <-- Here
'social_django.context_processors.login_redirect', # <-- Here
],
},
},
]
LOGIN_REDIRECT_URL = 'test'
LOGOUT_REDIRECT_URL = 'thanks'
SOCIAL_AUTH_FACEBOOK_KEY = '1289678764728890' # App ID
SOCIAL_AUTH_FACEBOOK_SECRET = '1c2a66c9c8116e4e2d97cb059db5d6a9' # App Secret
I need to get some information from LinkedIn profile of a user to fill existing fields of my application form. So I am using LinkedIn API(I have created app in linkedin and stand with client_Key, client_Secret,r_liteprofile and r_emailaddress permissions). Now it is prompting me to sign-in with linkedIn and asking for "Allow" permission(All OK till this prompt) but In the next page I'm getting below error instead of showing json file with user information.
"""
HTTPError at /complete/linkedin-oauth2/
410 Client Error: Gone for url: https://api.linkedin.com/v1/people/~:(first-name,id,last-name)?oauth2_access_token=AQVpVZCnhj2oLkzUvQytDU89kJUMm5yEIadV0BZMid3WVqPSVdOiJIePGIH7ZL7i3M5gppOlbUqpS68rDaaio56Y-nkC3Njpvf91v8WUPxQ8t-3uqJRzCC_MdrKUpntLalp24Eo2BMjpYIKeHGdxjFIlaMt9tszkIVHpPcZA2-dgbqOBrvt9-QE4P91bTXqBBkrtHEXg9F560OvltnQDgc0U1xwO-5yOT5LjlqAtvDJ_gMf3G8rZ9cdkayq4aP1CO-ljglGqlJb4uxorPRg7qPqqkNaAmQjXploM0KVQ6pK7nidP4zC2l7WW1aqg38GRDe8AM8jzaiIkg-SX3JfCJA28fT9H8A&format=json
"""
Below is my code, Did I miss anything....I'm newbie to Django Please help me to fix it??
I have tried to get exact access token format like{access token:XXXXX,expires in:XXX} with url https://www.linkedin.com/oauth/v2/accessToken?grant_type=client_credentials&client_id=[my_client_ID]&client_secret=[my_client_secret] I got below response.
{"error":"access_denied","error_description":"This application is not allowed to create application tokens"}
How can I achieve it??
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'crispy_forms',
'bootstrap4',
'social_django',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'social_django.middleware.SocialAuthExceptionMiddleware',
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'social_django.context_processors.backends',
'social_django.context_processors.login_redirect',
],
},
},
]
AUTHENTICATION_BACKENDS = (
'social.backends.linkedin.LinkedinOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
SOCIAL_AUTH_LINKEDIN_OAUTH2_KEY = 'my_client_ID'
SOCIAL_AUTH_LINKEDIN_OAUTH2_SECRET = 'my_client_secret'
SOCIAL_AUTH_LINKEDIN_OAUTH2_SCOPE = ['r_liteprofile']
SOCIAL_AUTH_LINKEDIN_OAUTH2_FIELD_SELECTORS = ['r_emailaddress']
SOCIAL_AUTH_LINKEDIN_OAUTH2_EXTRA_DATA = [('id', 'id'),
('firstName', 'first_name'),
('lastName', 'last_name'),
('emailAddress', 'email_address')]
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/home/'
SOCIAL_AUTH_LOGIN_URL = '/'
```[the error I'm getting][1]
[1]: https://i.stack.imgur.com/ECS3N.png
I made a new app for my webapp project using ./manage.py startapp webapplogin.
The templates all works however now I keep getting 'WSGIRequest' object has no attribute 'session' whenever I try to do anything with request such as logout(request) or login(request, user).
I don't understand what the issue is after about 6 hours of debugging/googling...
Do I need to go back to doing the webapp all in webapp instead of trying to split up the project into apps? The templating works fine as well as linking right now, just the no attribute 'session'...
project structure below
app_project
app_backend
settings.py
urls.py
wsgi.py
static
static_files
webapp
templates
webapp
base.html
home.html
admin.py
apps.py
models.py
tests.py
urls.py
views.py
webapplogin
templates
login
login.html
admin.py
apps.py
models.py
tests.py
urls.py
views.py
project settings below
INSTALLED_APPS = [
'webapplogin.apps.LoginConfig',
'webapp.apps.WebappConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'django.contrib.humanize',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'app_backend.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'app_backend.wsgi.application'
currently on 1.9, Django doesn't recognize the MIDDLEWARE setting. You should use the MIDDLEWARE_CLASSES setting
The reason this happens is because the order of the middleware is important.
During the request the Django session middleware must execute first in order to add the session object to the request.
Try the following :
MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
]
I'm trying to create a data visualization for yahoo finances, which I've successfully done locally using Django 1.9.2. It scrapes yahoo finances and then uses D3 to create bubble charts with tooltips.
However, the bubbles don't show up:
https://pure-woodland-72284.herokuapp.com/
This is what appears in Heroku logs.
Heroku Log Error Messages
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework_swagger',
'mysite'
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
# insert your TEMPLATE_DIRS here
os.path.join(os.path.dirname(__file__), 'templates'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
},
},
]
REST_FRAMEWORK={
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
]
}
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
Your console have the following errors:
Mixed Content: The page at 'https://pure-woodland-72284.herokuapp.com/' was loaded over HTTPS, but requested an insecure stylesheet 'http://fonts.googleapis.com/css?family=Lobster+Two:400,700italic'. This request has been blocked; the content must be served over HTTPS.
Hence you are getting 'Uncaught ReferenceError: $ is not defined' error since you did not really imported your libraries
So I'm guessing that you have imported your scripts (jquery,d3.tip,cssfonts) from their cdn and used http while importing. Try importing them with https and see if that solves your problem