Allauth Github is working without any problem, however, Twitter is not.
When clicking on https://0.0.0.0:9000/accounts/twitter/login/ nothing happens and yet there's no error. Everything is 200 ok.
I'm using SSL in dev environement using django-sslserver.
settings.py
INSTALLED_APPS = [
...
'django.contrib.sites', # new
'allauth', # new
'allauth.account', # new
'allauth.socialaccount', # new
'allauth.socialaccount.providers.github', # new
'allauth.socialaccount.providers.twitter', # new
'sslserver',
]
SOCIALACCOUNT_PROVIDERS = {'github': {}, 'twitter':{}}
AUTHENTICATION_BACKENDS = (
"django.contrib.auth.backends.ModelBackend",
"allauth.account.auth_backends.AuthenticationBackend",
)
SITE_ID = 1
LOGIN_REDIRECT_URL = '/'
I use example.com in my hosts' file:
/etc/hosts
0.0.0.0 example.com
And in the Twitter app, I use these configurations:
This is the social app configuration:
And the site configuration:
Do you see any problem?
The callback URL (can and) should be https://127.0.0.1:9000/accounts/twitter/login/callback/
This is how I solved this problem.
Related
I am getting a 403 error when trying to post to my Django server from my frontend mobile app. However, it works totally fine when I post with the form on the browser.
I managed to register once using my frontend mobile app, but ever since then, I get this 403 error. I've tried both signing up and logging in.
Here is the error I get in my Django backend terminal:
Bad Request: /rest-auth/registration/
[16/Aug/2021 14:51:37] "POST /rest-auth/registration/ HTTP/1.1" 403 58
Here is my settings.py file:
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',
'rest_auth',
'django.contrib.sites',
'allauth',
'allauth.account',
'rest_auth.registration',
'users',
]
SITE_ID = 1
....
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
),
}
ACCOUNT_EMAIL_VERIFICATION = 'none'
Here is my front end (register.js):
axios
.post("http://127.0.0.1:8002/rest-auth/registration/", {
username: "tester1234#gmail.com",
email: "tester1234#gmail.com",
password1: "tester1234#gmail.com",
password2: "tester1234#gmail.com",
})
What am I doing wrong? I just want users to be able to register, log in, and log out of my app.
The issue was that I had logged in, and then was not providing the key.
To solve this, I created a logout button, then added a mechanism to save the key and use it in the header.
I am fairly new to the rest api. I am trying to use dj-rest-auth package with simple-jwt for auth handling. Everything works fine in my project. The registration/login etc. But in my django admin site there is a model registered Token which is every time empty. What is the purpose of this model Token? How tokens are managed with dj-rest-auth and simple jwt package ?
settings.py
installed_apps= [
..
'rest_framework',
'rest_framework.authtoken',
'dj_rest_auth',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'dj_rest_auth.registration',
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
)
}
REST_USE_JWT = True
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=5),
'REFRESH_TOKEN_LIFETIME': timedelta(days=7),
}
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 1
ACCOUNT_AUTHENTICATION_METHOD = "username"
ACCOUNT_LOGIN_ATTEMPTS_LIMIT = None
urls.py
path('user/', include('dj_rest_auth.urls')),
path('user/register/', include('dj_rest_auth.registration.urls')),
path('confirm/email/', CustomVerifyEmailView.as_view(), name='account_email_verification_sent'),
You have Token model in admin because you added rest_framework.authtoken to your installed apps. This model is for basic token (stored in db) authentication: https://www.django-rest-framework.org/api-guide/authentication/#tokenauthentication
JWT (JSON Web Tokens) tokens are stateless and are not stored in db. If you want to read more about JWT I recommend: https://jwt.io/introduction
I have a really weird situation I cannot seem to figure out. I have not touched my implementation of this package since the beginning of the year and now the functionality ceases to exist on my live heroku server. I currently have a Create Account form on my public tenant which generates a tenant/domain just as the docs do and django-tenants does its auto schema generation. This works correctly on my localhost and have zero problems. However on my live server, I proceed to get a 404 error... Not Found...The requested URL / was not found on this server.
I have a CNAME record on DNSimple which points to a wildcard domain that appears to be working, because I have already have a tenant I made awhile ago that is still completely functional (ie. some-customer.mydomain.com). I have looked into my PSQL db attached to heroku and everything is there as it should be, as well as the migrations occurring in the logs when I create an account which generates a tenant.
I was hoping that there might be some enlightenment as to what I am doing/have done wrong to make this issue occur. It just seems so odd that none of my now generated tenants can be accessed via their Domain.
Edit: Posting Code.
local .env file
SECRET_KEY=...
DEBUG=True
DB_NAME=...
DB_USER=...
DB_PASSWORD=...
DB_HOST=localhost
ALLOWED_HOSTS=.localhost, .herokuapp.com
GOOGLE_RECAPTCHA_SECRET_KEY=...
AWS_ACCESS_KEY_ID=...
AWS_SECRET_ACCESS_KEY=...
AWS_STORAGE_BUCKET_NAME=...
SECURE_SSL_REDIRECT='False'
settings.py (included things I think are relative)
...
LOGIN_URL = 'login'
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default=[], cast=Csv())
DEBUG = config('DEBUG', default=False, cast=bool)
SECRET_KEY = config('SECRET_KEY')
SHARED_APPS = (
'django_tenants',
'tenant',
'django.contrib.contenttypes',
'public.apps.PublicConfig',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.sessions',
'debug_toolbar',
'storages'
)
TENANT_APPS = (
'django.contrib.contenttypes',
'inventory.apps.InventoryConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
)
INSTALLED_APPS = list(SHARED_APPS) + [app for app in TENANT_APPS if app not in SHARED_APPS]
TENANT_MODEL = 'tenant.Client'
TENANT_DOMAIN_MODEL = 'tenant.Domain'
MIDDLEWARE = [
'django_tenants.middleware.main.TenantMainMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
]
ROOT_URLCONF = 'myapp.urls'
WSGI_APPLICATION = 'myapp.wsgi.application'
DATABASE_ROUTERS = (
'django_tenants.routers.TenantSyncRouter',
)
PUBLIC_SCHEMA_URLCONF = 'myapp.urls_public'
SECURE_SSL_REDIRECT = config('SECURE_SSL_REDIRECT', default=False, cast=bool)
...
production Heroku settings (included relative stuff)
...
ALLOWED_HOSTS: .herokuapp.com, .mydomain.com, mydomain.com
DEBUG: False
SECURE_SSL_REDIRECT: True
...
urls.py (each tenant should see these)
urlpatterns = [
...
url(r'^$', dashboard, name='dashboard'),
url(r'^login/$', login_view, name='login'),
url(r'^logout/$', logout_view, name='logout'),
...
]
urls_public.py (main site)
urlpatterns = [
url(r'^$', home_view, name='home'),
url(r'^login/$', login_view, name='login'),
url(r'^logout/$', logout_view, name='logout'),
url(r'^create_account/$', create_account_view, name='create_account'),
]
Everything seems to look fine. If you try generating a tenant using the django-tenant docs in the shell on your production server by doing heroku run python manage.py shell -a yourapp and that works, then there is something wrong with your code that generates the tenants which you have not posted.
I want to use the allauth django app.
I did everything described in this allauth tutorial: http://www.sarahhagstrom.com/2013/09/the-missing-django-allauth-tutorial/. I continues until "Now we can login using Django or Facebook" subpart.
After that I can't go to the address that is indicated in the tutorial: http://127.0.0.1:8000/accounts/login/
I want you to see the database that I have. its exatly like the tutorial indicates:
This is my setting.py file:
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
"/srv/http/proj04/proj/templates",
)
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
"django.contrib.auth.backends.ModelBackend",
# `allauth` specific authentication methods, such as login by e-mail
"allauth.account.auth_backends.AuthenticationBackend"
)
TEMPLATE_CONTEXT_PROCESSORS = (
# Required by allauth template tags
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.request",
# allauth specific context processors
"allauth.account.context_processors.account",
"allauth.socialaccount.context_processors.socialaccount",
)
LOGIN_REDIRECT_URL = '/'
SOCIALACCOUNT_QUERY_EMAIL = True
SOCIALACCOUNT_PROVIDERS = {
'google': {
'SCOPE': ['email', 'publish_stream'],
'METHOD': 'oauth2' # instead of 'oauth2'
}
}
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp',
'captcha',
'django.contrib.admin',
# Uncomment the next line to enable the admin:
# Uncomment the next line to enable admin documentation:
'allauth',
'allauth.account',
'allauth.socialaccount',
# ... include the providers you want to enable:
'allauth.socialaccount.providers.amazon',
'allauth.socialaccount.providers.dropbox',
'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.flickr',
'allauth.socialaccount.providers.google',
'allauth.socialaccount.providers.instagram',
'allauth.socialaccount.providers.linkedin',
'allauth.socialaccount.providers.linkedin_oauth2',
'allauth.socialaccount.providers.openid',
'allauth.socialaccount.providers.tumblr',
'allauth.socialaccount.providers.twitter',
'allauth.socialaccount.providers.vimeo',
'allauth.socialaccount.providers.vk',
# 'django.contrib.admindocs',
)
This is my url.py file:
....
admin.autodiscover()
urlpatterns = patterns('',
(r'^accounts/', include('allauth.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
urlpatterns += [
# ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
I don;t know what to do next.
I tried
http://127.0.0.1:8000/accounts/login/
Only to get this exception:
DoesNotExist at /accounts/login/
Site matching query does not exist.
Request Method: GET
Request URL: http://127.0.0.1:8000/accounts/login/
Django Version: 1.6.5
Exception Type: DoesNotExist
Exception Value:
Site matching query does not exist.
Exception Location: /srv/http/proj04/lib/python3.4/site-packages/django/db/models/query.py in get, line 310
Python Executable: /srv/http/proj04/bin/python
Python Version: 3.4.1
...
or sometimes i get this exception ( i dont know why but these exception alternate):
ImproperlyConfigured at /accounts/login/
No Facebook app configured: please add a SocialApp using the Django admin
Request Method: GET
Request URL: http://127.0.0.1:8000/accounts/login/
Django Version: 1.6.5
Exception Type: ImproperlyConfigured
Exception Value:
No Facebook app configured: please add a SocialApp using the Django admin
Exception Location: /srv/http/proj04/lib/python3.4/site-packages/allauth/socialaccount/providers/facebook/provider.py in media_js, line 106
Python Executable: /srv/http/proj04/bin/python
Python Version: 3.4.1
What am I missing?
Thanks in advance.
You need to modify your allauth google settings in your app settings. Take a look at the docs to see what settings are avaliable.
http://django-allauth.readthedocs.org/en/latest/#google
You'll also need to change your installed apps to only include these allauth apps
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google'
Add "SITE_ID" in settings.py
django_site table must contain a row with the same value of id (by default equals to 1), as SITE_ID.
And in your SocialApplication table 'localhost:8000/admin/socialaccount/socialapp/' for different providers give this site ID and try to run again, it will work.
i saw some topic about my problem however i didn' t find the solution for it and i don' t know what i' m doing wrong.
Since this is a test system,
i delete my whole db
i run syncdb && migrate to have everything clear.
i set the SITE_ID to 1
i restart apache2 (well, not using development server at the moment)
in the admin -> Sites -> Sites section i set the example.com to mysub.mydomain.com (for both the display name and domain name)
in the admin -> Socialaccount -> Social apps section i add a new app:
provider: facebook
name: the same name than on developers.facebook.com
client id: App ID/API Key from developers.facebook.com
Key: stays None
Secret: App Secret from developers.facebook.com
Chosen sites: i move here the only one existing which is mysub.mydomain.com (on developers.facebook.com i' ve the same mysub.mydomain.com at App Domains)
in the settings.py file i' ve these relevant sections:
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
)
INSTALLED_APPS = (...,
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
)
TEMPLATE_CONTEXT_PROCESSORS += ('common.context_processors.add_app_name',
'django.core.context_processors.request',
'allauth.account.context_processors.account',
'allauth.socialaccount.context_processors.socialaccount',)
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
SOCIALACCOUNT_PROVIDERS = \
{ 'facebook':
{ 'SCOPE': ['email'],
'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
'METHOD': 'oauth2',
'LOCALE_FUNC': lambda request: 'en_US',
}
}
to the urls.py: url(r'^accounts/', include('allauth.urls')),
. After all these (and apache2 restart) when i go to mysub.mydomain.com/accounts/login/ (i log out from admin at first) i got the same error than for example here:
Django-allauth No Facebook app configured: please add a SocialApp using the Django admin
. I don' t really know what else can be the problem but i' d be happy if someone could point me to the right direction or to tell me what else to check.
Thanks.