Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why im getting invalid client error while trying to post in postman #256

Open
galomari opened this issue Oct 15, 2022 · 2 comments
Open

Comments

@galomari
Copy link

galomari commented Oct 15, 2022

hi i was trying to post in postman using some parameters like client_id and client secret and token which i got it from Facebook[enter image description here][2] developer app
#here is my reqest
url:http://localhost:8000/api/social/convert-token?grant_type=convert_token&client_id=sdklhsjgvdshfuahhddkaj37637utydew7&client_secret=dgshjhsdfkgaskflj8363589klsskjnlksfjnljhfjmj83889ij&backend=facebook&token=lkdfjlkjhdsfkljhbdsncvkjdsh763uhkdjcbgjhxsgckjdsh7ytfgklfclkfoit76ejvmljfdlkjndsi736uihd

#postman

#also my setting.py

from pathlib import Path

Build paths inside the project like this: BASE_DIR / 'subdir'.

BASE_DIR = Path(file).resolve().parent.parent

Quick-start development settings - unsuitable for production

See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

SECURITY WARNING: keep the secret key used in production secret!

SECURITY WARNING: don't run with debug turned on in production!

DEBUG = True

ALLOWED_HOSTS = []

Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'coreapp',
'cloudinary',
'oauth2_provider',
'social_django',
'rest_framework_social_oauth2',
]

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 = 'foodhub.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',
'social_django.context_processors.backends',
'social_django.context_processors.login_redirect',
],
},
},
]

WSGI_APPLICATION = 'foodhub.wsgi.application'

Database

https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}

Password validation

https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]

Internationalization

https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

Static files (CSS, JavaScript, Images)

https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = '/static/'

Default primary key field type

https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

LOGIN_REDIRECT_URL='/'
import cloudinary
import cloudinary.uploader
import cloudinary.api

#config heroku
import django_heroku
django_heroku.settings(locals())

#CSRF_TRUSTED_ORIGINS =['http://127.0.0.1:8000/restaurant/sign_up']

AUTHENTICATION_BACKENDS = (
'social_core.backends.facebook.FacebookOAuth2',
'django.contrib.auth.backends.ModelBackend',
)

Facebook configuration

SOCIAL_AUTH_FACEBOOK_KEY = 'FACEBOOK_KEY'
SOCIAL_AUTH_FACEBOOK_SECRET = 'facebook_secret'

Define SOCIAL_AUTH_FACEBOOK_SCOPE to get extra permissions from Facebook.

Email is not sent by default, to get it, you must request the email permission.

SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {
'fields': 'id, name, email,picture.type(large)'

the url.py

from re import template
from django.contrib import admin
from django.urls import path,include
from django.contrib.auth import views as auth_views
from django.contrib.auth import views
from coreapp import views

urlpatterns = [
#Web View - Admin
path('admin/', admin.site.urls),
path('', views.home,name='home'),

#web View - Restaurant
path('restaurant/sign_in/',auth_views.LoginView.as_view(template_name='restaurant/sign_in.html'),name='restaurant_sign_in'),
path('restaurant/sign_out/',auth_views.LogoutView.as_view(next_page='/'),name='restaurant_sign_out'),
path('restaurant/sign_up', views.restaurant_sign_up,name='restaurant_sign_up'),
 path('restaurant/', views.restaurant_home,name='restaurant_home'),
 
 #APIs
 # /convert-token (sing_in/sing_up) ,/revoke-token(sign-out)
path('api/social/', include('rest_framework_social_oauth2.urls')),

]

@Madhu25666
Copy link

You should copy the client secret before it is hashed in the django admin. The client secret is hashed when you save the settings.

@satvik6005
Copy link

yepp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants