This is an example, how to implement standard basic oauth. With out any added complexity through the specific app it gets build into.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
3.8 KiB

  1. """
  2. Django settings for oauth_demo project.
  3. Generated by 'django-admin startproject' using Django 3.0.5.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/3.0/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/3.0/ref/settings/
  8. """
  9. import os
  10. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  11. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  12. # Quick-start development settings - unsuitable for production
  13. # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
  14. # SECURITY WARNING: keep the secret key used in production secret!
  15. SECRET_KEY = '#jk+74g_ilb4h)f!_20mmcg^5-+veuj2(v%0ufymq+r%mc3im-'
  16. # SECURITY WARNING: don't run with debug turned on in production!
  17. DEBUG = True
  18. ALLOWED_HOSTS = []
  19. # Application definition
  20. INSTALLED_APPS = [
  21. 'django.contrib.admin',
  22. 'django.contrib.auth',
  23. 'django.contrib.contenttypes',
  24. 'django.contrib.sessions',
  25. 'django.contrib.messages',
  26. 'django.contrib.staticfiles',
  27. ]
  28. MIDDLEWARE = [
  29. 'django.middleware.security.SecurityMiddleware',
  30. 'django.contrib.sessions.middleware.SessionMiddleware',
  31. 'django.middleware.common.CommonMiddleware',
  32. 'django.middleware.csrf.CsrfViewMiddleware',
  33. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  34. 'django.contrib.messages.middleware.MessageMiddleware',
  35. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  36. 'oauth_demo.middleware.oauth.OAuthMiddleware'
  37. ]
  38. ROOT_URLCONF = 'oauth_demo.urls'
  39. TEMPLATES = [
  40. {
  41. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  42. 'DIRS': [os.path.join(BASE_DIR, 'templates')]
  43. ,
  44. 'APP_DIRS': True,
  45. 'OPTIONS': {
  46. 'context_processors': [
  47. 'django.template.context_processors.debug',
  48. 'django.template.context_processors.request',
  49. 'django.contrib.auth.context_processors.auth',
  50. 'django.contrib.messages.context_processors.messages',
  51. ],
  52. },
  53. },
  54. ]
  55. WSGI_APPLICATION = 'oauth_demo.wsgi.application'
  56. # Database
  57. # https://docs.djangoproject.com/en/3.0/ref/settings/#databases
  58. DATABASES = {
  59. 'default': {
  60. 'ENGINE': 'django.db.backends.sqlite3',
  61. 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
  62. }
  63. }
  64. # Password validation
  65. # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
  66. AUTH_PASSWORD_VALIDATORS = [
  67. {
  68. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  69. },
  70. {
  71. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  72. },
  73. {
  74. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  75. },
  76. {
  77. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  78. },
  79. ]
  80. # Internationalization
  81. # https://docs.djangoproject.com/en/3.0/topics/i18n/
  82. LANGUAGE_CODE = 'en-us'
  83. TIME_ZONE = 'UTC'
  84. USE_I18N = True
  85. USE_L10N = True
  86. USE_TZ = True
  87. # Static files (CSS, JavaScript, Images)
  88. # https://docs.djangoproject.com/en/3.0/howto/static-files/
  89. STATIC_URL = '/static/'
  90. # OAuth Settings
  91. OAUTH_URL_WHITELISTS = []
  92. OAUTH_CLIENT_NAME = '<name-of-the-configured-wikimedia-app>'
  93. OAUTH_CLIENT = {
  94. 'client_id': '<client-application-key-of-wikimedia-app>',
  95. 'client_secret': '<client-application-secret-of-wikimedia-app>',
  96. 'access_token_url': 'https://meta.wikimedia.org/w/rest.php/oauth2/access_token',
  97. 'authorize_url': 'https://meta.wikimedia.org/w/rest.php/oauth2/authorize',
  98. 'api_base_url': 'https://meta.wikimedia.org/w/rest.php/oauth2/resource',
  99. 'redirect_uri': 'http://localhost:8000/oauth/callback',
  100. 'client_kwargs': {
  101. 'scope': 'basic',
  102. 'token_placement': 'header'
  103. },
  104. 'userinfo_endpoint': 'resource/profile',
  105. }
  106. OAUTH_COOKIE_SESSION_ID = 'sso_session_id'