Add mock OAuth2 provider to testproj
This commit is contained in:
1 parent
bbed2acf06
commit
b385228f7d
7 files changed
+116
-5
No files matched your search
@@ -8,3 +8,4 @@ djangorestframework-camel-case>=0.2.0
|
||||
djangorestframework-recursive>=0.1.2
|
||||
dj-database-url>=0.4.2
|
||||
user_agents>=1.1.0
|
||||
django-oauth-toolkit>=1.2.0
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 2.1.3 on 2018-12-19 08:16
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('snippets', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='snippet',
|
||||
name='language',
|
||||
field=models.CharField(choices=[('abap', 'ABAP'), ('abnf', 'ABNF'), ('ada', 'Ada'), ('adl', 'ADL'), ('agda', 'Agda'), ('aheui', 'Aheui'), ('ahk', 'autohotkey'), ('alloy', 'Alloy'), ('ampl', 'Ampl'), ('antlr', 'ANTLR'), ('antlr-as', 'ANTLR With ActionScript Target'), ('antlr-cpp', 'ANTLR With CPP Target'), ('antlr-csharp', 'ANTLR With C# Target'), ('antlr-java', 'ANTLR With Java Target'), ('antlr-objc', 'ANTLR With ObjectiveC Target'), ('antlr-perl', 'ANTLR With Perl Target'), ('antlr-python', 'ANTLR With Python Target'), ('antlr-ruby', 'ANTLR With Ruby Target'), ('apacheconf', 'ApacheConf'), ('apl', 'APL'), ('applescript', 'AppleScript'), ('arduino', 'Arduino'), ('as', 'ActionScript'), ('as3', 'ActionScript 3'), ('aspectj', 'AspectJ'), ('aspx-cs', 'aspx-cs'), ('aspx-vb', 'aspx-vb'), ('asy', 'Asymptote'), ('at', 'AmbientTalk'), ('autoit', 'AutoIt'), ('awk', 'Awk'), ('basemake', 'Base Makefile'), ('bash', 'Bash'), ('bat', 'Batchfile'), ('bbcode', 'BBCode'), ('bc', 'BC'), ('befunge', 'Befunge'), ('bib', 'BibTeX'), ('blitzbasic', 'BlitzBasic'), ('blitzmax', 'BlitzMax'), ('bnf', 'BNF'), ('boo', 'Boo'), ('boogie', 'Boogie'), ('brainfuck', 'Brainfuck'), ('bro', 'Bro'), ('bst', 'BST'), ('bugs', 'BUGS'), ('c', 'C'), ('c-objdump', 'c-objdump'), ('ca65', 'ca65 assembler'), ('cadl', 'cADL'), ('camkes', 'CAmkES'), ('capdl', 'CapDL'), ('capnp', "Cap'n Proto"), ('cbmbas', 'CBM BASIC V2'), ('ceylon', 'Ceylon'), ('cfc', 'Coldfusion CFC'), ('cfengine3', 'CFEngine3'), ('cfm', 'Coldfusion HTML'), ('cfs', 'cfstatement'), ('chai', 'ChaiScript'), ('chapel', 'Chapel'), ('cheetah', 'Cheetah'), ('cirru', 'Cirru'), ('clay', 'Clay'), ('clean', 'Clean'), ('clojure', 'Clojure'), ('clojurescript', 'ClojureScript'), ('cmake', 'CMake'), ('cobol', 'COBOL'), ('cobolfree', 'COBOLFree'), ('coffee-script', 'CoffeeScript'), ('common-lisp', 'Common Lisp'), ('componentpascal', 'Component Pascal'), ('console', 'Bash Session'), ('control', 'Debian Control file'), ('coq', 'Coq'), ('cpp', 'C++'), ('cpp-objdump', 'cpp-objdump'), ('cpsa', 'CPSA'), ('cr', 'Crystal'), ('crmsh', 'Crmsh'), ('croc', 'Croc'), ('cryptol', 'Cryptol'), ('csharp', 'C#'), ('csound', 'Csound Orchestra'), ('csound-document', 'Csound Document'), ('csound-score', 'Csound Score'), ('css', 'CSS'), ('css+django', 'CSS+Django/Jinja'), ('css+erb', 'CSS+Ruby'), ('css+genshitext', 'CSS+Genshi Text'), ('css+lasso', 'CSS+Lasso'), ('css+mako', 'CSS+Mako'), ('css+mozpreproc', 'CSS+mozpreproc'), ('css+myghty', 'CSS+Myghty'), ('css+php', 'CSS+PHP'), ('css+smarty', 'CSS+Smarty'), ('cucumber', 'Gherkin'), ('cuda', 'CUDA'), ('cypher', 'Cypher'), ('cython', 'Cython'), ('d', 'D'), ('d-objdump', 'd-objdump'), ('dart', 'Dart'), ('delphi', 'Delphi'), ('dg', 'dg'), ('diff', 'Diff'), ('django', 'Django/Jinja'), ('docker', 'Docker'), ('doscon', 'MSDOS Session'), ('dpatch', 'Darcs Patch'), ('dtd', 'DTD'), ('duel', 'Duel'), ('dylan', 'Dylan'), ('dylan-console', 'Dylan session'), ('dylan-lid', 'DylanLID'), ('earl-grey', 'Earl Grey'), ('easytrieve', 'Easytrieve'), ('ebnf', 'EBNF'), ('ec', 'eC'), ('ecl', 'ECL'), ('eiffel', 'Eiffel'), ('elixir', 'Elixir'), ('elm', 'Elm'), ('emacs', 'EmacsLisp'), ('erb', 'ERB'), ('erl', 'Erlang erl session'), ('erlang', 'Erlang'), ('evoque', 'Evoque'), ('extempore', 'xtlang'), ('ezhil', 'Ezhil'), ('factor', 'Factor'), ('fan', 'Fantom'), ('fancy', 'Fancy'), ('felix', 'Felix'), ('fennel', 'Fennel'), ('fish', 'Fish'), ('flatline', 'Flatline'), ('forth', 'Forth'), ('fortran', 'Fortran'), ('fortranfixed', 'FortranFixed'), ('foxpro', 'FoxPro'), ('fsharp', 'FSharp'), ('gap', 'GAP'), ('gas', 'GAS'), ('genshi', 'Genshi'), ('genshitext', 'Genshi Text'), ('glsl', 'GLSL'), ('gnuplot', 'Gnuplot'), ('go', 'Go'), ('golo', 'Golo'), ('gooddata-cl', 'GoodData-CL'), ('gosu', 'Gosu'), ('groff', 'Groff'), ('groovy', 'Groovy'), ('gst', 'Gosu Template'), ('haml', 'Haml'), ('handlebars', 'Handlebars'), ('haskell', 'Haskell'), ('haxeml', 'Hxml'), ('hexdump', 'Hexdump'), ('hlsl', 'HLSL'), ('hsail', 'HSAIL'), ('html', 'HTML'), ('html+cheetah', 'HTML+Cheetah'), ('html+django', 'HTML+Django/Jinja'), ('html+evoque', 'HTML+Evoque'), ('html+genshi', 'HTML+Genshi'), ('html+handlebars', 'HTML+Handlebars'), ('html+lasso', 'HTML+Lasso'), ('html+mako', 'HTML+Mako'), ('html+myghty', 'HTML+Myghty'), ('html+ng2', 'HTML + Angular2'), ('html+php', 'HTML+PHP'), ('html+smarty', 'HTML+Smarty'), ('html+twig', 'HTML+Twig'), ('html+velocity', 'HTML+Velocity'), ('http', 'HTTP'), ('hx', 'Haxe'), ('hybris', 'Hybris'), ('hylang', 'Hy'), ('i6t', 'Inform 6 template'), ('idl', 'IDL'), ('idris', 'Idris'), ('iex', 'Elixir iex session'), ('igor', 'Igor'), ('inform6', 'Inform 6'), ('inform7', 'Inform 7'), ('ini', 'INI'), ('io', 'Io'), ('ioke', 'Ioke'), ('irc', 'IRC logs'), ('isabelle', 'Isabelle'), ('j', 'J'), ('jags', 'JAGS'), ('jasmin', 'Jasmin'), ('java', 'Java'), ('javascript+mozpreproc', 'Javascript+mozpreproc'), ('jcl', 'JCL'), ('jlcon', 'Julia console'), ('js', 'JavaScript'), ('js+cheetah', 'JavaScript+Cheetah'), ('js+dLine truncated
|
||||
),
|
||||
]
|
||||
@@ -3,6 +3,8 @@ import os
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
from django.urls import reverse_lazy
|
||||
|
||||
from testproj.util import full_url_lazy, static_lazy
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
ALLOWED_HOSTS = [
|
||||
@@ -22,6 +24,7 @@ INSTALLED_APPS = [
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'rest_framework',
|
||||
'oauth2_provider',
|
||||
'corsheaders',
|
||||
|
||||
'drf_yasg',
|
||||
@@ -64,6 +67,8 @@ TEMPLATES = [
|
||||
|
||||
WSGI_APPLICATION = 'testproj.wsgi.application'
|
||||
|
||||
LOGIN_URL = reverse_lazy('admin:login')
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
|
||||
|
||||
@@ -90,8 +95,15 @@ REST_FRAMEWORK = {
|
||||
)
|
||||
}
|
||||
|
||||
# drf-yasg
|
||||
OAUTH2_CLIENT_ID = '12ee6bgxtpSEgP8TioWcHSXOiDBOUrVav4mRbVEs'
|
||||
OAUTH2_CLIENT_SECRET = '5FvYALo7W4uNnWE2ySw7Yzpkxh9PSf5GuY37RvOys00ydEyph64dbl1ECOKI9ceQAKoz0JpiVQtq0DUnsxNhU3ubrJgZ9YbtiXymbLGJq8L7n4fiER7gXbXaNSbze3BN'
|
||||
OAUTH2_APP_NAME = 'drf-yasg OAuth2 provider'
|
||||
|
||||
OAUTH2_REDIRECT_URL = full_url_lazy(static_lazy('drf-yasg/swagger-ui-dist/oauth2-redirect.html'))
|
||||
OAUTH2_AUTHORIZE_URL = full_url_lazy(reverse_lazy('oauth2_provider:authorize'))
|
||||
OAUTH2_TOKEN_URL = full_url_lazy(reverse_lazy('oauth2_provider:token'))
|
||||
|
||||
# drf-yasg
|
||||
SWAGGER_SETTINGS = {
|
||||
'LOGIN_URL': reverse_lazy('admin:login'),
|
||||
'LOGOUT_URL': '/admin/logout',
|
||||
@@ -114,7 +126,22 @@ SWAGGER_SETTINGS = {
|
||||
'type': 'apiKey',
|
||||
'name': 'auth',
|
||||
'in': 'query'
|
||||
},
|
||||
'OAuth2 password': {
|
||||
'type': 'oauth2',
|
||||
'flow': 'password',
|
||||
'tokenUrl': OAUTH2_TOKEN_URL,
|
||||
'scopes': {
|
||||
'read': 'Read everything.',
|
||||
'write': 'Write everything,',
|
||||
}
|
||||
}
|
||||
},
|
||||
'OAUTH2_REDIRECT_URL': OAUTH2_REDIRECT_URL,
|
||||
'OAUTH2_CONFIG': {
|
||||
'clientId': OAUTH2_CLIENT_ID,
|
||||
'clientSecret': OAUTH2_CLIENT_SECRET,
|
||||
'appName': OAUTH2_APP_NAME,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,13 +153,9 @@ REDOC_SETTINGS = {
|
||||
# https://docs.djangoproject.com/en/1.11/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_L10N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
|
||||
@@ -60,6 +60,8 @@ urlpatterns = [
|
||||
url(r'^$', root_redirect),
|
||||
|
||||
url(r'^admin/', admin.site.urls),
|
||||
url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
|
||||
|
||||
url(r'^snippets/', include('snippets.urls')),
|
||||
url(r'^articles/', include('articles.urls')),
|
||||
url(r'^users/', include('users.urls')),
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
from django.contrib.staticfiles.templatetags.staticfiles import static
|
||||
from django.urls import NoReverseMatch
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.functional import lazy
|
||||
|
||||
|
||||
def full_url(absolute_path):
|
||||
try:
|
||||
return "http://test.local:8002" + force_text(absolute_path)
|
||||
except NoReverseMatch:
|
||||
# if absolute_path is a resolve_lazy, it might point to an invalid name
|
||||
# just ignore it if it does
|
||||
return "http://test.local:8002/no-reverse-match/"
|
||||
|
||||
|
||||
full_url_lazy = lazy(full_url, str, type(None))
|
||||
static_lazy = lazy(static, str)
|
||||
@@ -0,0 +1,42 @@
|
||||
# Generated by Django 2.1.3 on 2018-12-19 07:57
|
||||
from django.conf import settings
|
||||
from django.contrib.staticfiles.templatetags.staticfiles import static
|
||||
from django.db import migrations, IntegrityError
|
||||
|
||||
from testproj.util import full_url_lazy
|
||||
|
||||
|
||||
def add_oauth_apps(apps, schema_editor):
|
||||
# We can't import the Person model directly as it may be a newer
|
||||
# version than this migration expects. We use the historical version.
|
||||
User = apps.get_model(settings.AUTH_USER_MODEL)
|
||||
Application = apps.get_model('oauth2_provider', 'application')
|
||||
|
||||
user = User.objects.get(username='admin')
|
||||
|
||||
oauth2_apps = [
|
||||
{
|
||||
"user": user,
|
||||
"client_type": "public",
|
||||
"authorization_grant_type": "password",
|
||||
"client_id": settings.OAUTH2_CLIENT_ID,
|
||||
"client_secret": settings.OAUTH2_CLIENT_SECRET,
|
||||
"redirect_uris": settings.OAUTH2_REDIRECT_URL,
|
||||
"name": settings.OAUTH2_APP_NAME
|
||||
}
|
||||
]
|
||||
|
||||
for app in oauth2_apps:
|
||||
Application.objects.get_or_create(client_id=app['client_id'], defaults=app)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('oauth2_provider', '0006_auto_20171214_2232'),
|
||||
('users', '0001_create_admin_user'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(add_oauth_apps)
|
||||
]
|
||||
@@ -27,6 +27,13 @@ securityDefinitions:
|
||||
in: header
|
||||
name: Authorization
|
||||
type: apiKey
|
||||
OAuth2 password:
|
||||
flow: password
|
||||
scopes:
|
||||
read: Read everything.
|
||||
write: Write everything,
|
||||
tokenUrl: http://test.local:8002/o/token/
|
||||
type: oauth2
|
||||
Query:
|
||||
in: query
|
||||
name: auth
|
||||
@@ -34,6 +41,7 @@ securityDefinitions:
|
||||
security:
|
||||
- Basic: []
|
||||
- Bearer: []
|
||||
- OAuth2 password: []
|
||||
- Query: []
|
||||
paths:
|
||||
/articles/:
|
||||
|
||||
Reference in new issue
Block a user