Hi there
21 |
24 | Client_id: {{client_id}}
25 | Client_secret: {{client_secret}}
26 |
├── userservice ├── oauth │ ├── __init__.py │ ├── migrations │ │ └── __init__.py │ ├── tests.py │ ├── admin.py │ ├── models.py │ ├── apps.py │ ├── forms.py │ ├── templates │ │ └── oauth │ │ │ ├── oauth.html │ │ │ ├── applications.html │ │ │ └── base.html │ ├── views.py │ └── kong.py ├── userservice │ ├── __init__.py │ ├── wsgi.py │ ├── urls.py │ └── settings.py ├── requirements.txt ├── db.sqlite3 ├── Dockerfile └── manage.py ├── client ├── requirements.txt ├── Dockerfile ├── index.html ├── app.py └── templates │ └── index.html ├── .gitignore ├── service1 ├── Dockerfile ├── app.js └── package.json ├── service2 ├── Dockerfile ├── app.js └── package.json ├── register2.sh ├── environment.env ├── register.sh ├── LICENSE ├── docker-compose.yml └── README.md /userservice/oauth/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /userservice/userservice/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /userservice/oauth/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /client/requirements.txt: -------------------------------------------------------------------------------- 1 | Flask 2 | requests 3 | -------------------------------------------------------------------------------- /userservice/requirements.txt: -------------------------------------------------------------------------------- 1 | django>=1.9 2 | requests 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | __pycache__ 3 | .DS_Store 4 | *.pyc 5 | -------------------------------------------------------------------------------- /userservice/oauth/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /userservice/oauth/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /service1/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:5 2 | RUN mkdir /code 3 | WORKDIR /code 4 | ADD . /code/ 5 | #RUN npm install 6 | -------------------------------------------------------------------------------- /userservice/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/toast38coza/docker-kong-oauth/HEAD/userservice/db.sqlite3 -------------------------------------------------------------------------------- /service2/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:5 2 | RUN mkdir /code 3 | WORKDIR /code 4 | ADD . /code/ 5 | #RUN npm install express 6 | -------------------------------------------------------------------------------- /userservice/oauth/models.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | 3 | from django.db import models 4 | 5 | # Create your models here. 6 | -------------------------------------------------------------------------------- /userservice/oauth/apps.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | 3 | from django.apps import AppConfig 4 | 5 | 6 | class AuthConfig(AppConfig): 7 | name = 'auth' 8 | -------------------------------------------------------------------------------- /client/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.5 2 | ENV PYTHONUNBUFFERED 1 3 | RUN mkdir /code 4 | WORKDIR /code 5 | ADD requirements.txt /code/ 6 | RUN pip install -r requirements.txt 7 | ADD . /code/ 8 | -------------------------------------------------------------------------------- /register2.sh: -------------------------------------------------------------------------------- 1 | curl -X POST http://docker.local:8001/apis/$1/plugins \ 2 | --data "name=oauth2" 3 | curl -X POST http://docker.local:8001/apis/$2/plugins \ 4 | --data "name=oauth2" 5 | -------------------------------------------------------------------------------- /userservice/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.5 2 | ENV PYTHONUNBUFFERED 1 3 | RUN mkdir /code 4 | WORKDIR /code 5 | ADD requirements.txt /code/ 6 | RUN pip install -r requirements.txt 7 | ADD . /code/ 8 | -------------------------------------------------------------------------------- /environment.env: -------------------------------------------------------------------------------- 1 | client_id=63072dd44bee4403a1b0c69564c7ebed 2 | client_secret=9a49af96afac49b78319ce0a18e6afc5 3 | kong_url=https://192.168.99.100:8443 4 | kong_admin_url=http://192.168.99.100:8001 5 | -------------------------------------------------------------------------------- /service2/app.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var app = express(); 3 | 4 | app.get('/', function (req, res) { 5 | res.send('Hello Something Else!'); 6 | }); 7 | 8 | app.listen(3000, function () { 9 | console.log('Example app listening on port 3000!'); 10 | }); 11 | -------------------------------------------------------------------------------- /service1/app.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var app = express(); 3 | 4 | app.get('/', function (req, res) { 5 | console.log("here .."); 6 | res.send('Hello World!'); 7 | }); 8 | 9 | app.listen(3000, function () { 10 | console.log('Example app listening on port 3000! asdasds'); 11 | }); 12 | -------------------------------------------------------------------------------- /userservice/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "userservice.settings") 7 | 8 | from django.core.management import execute_from_command_line 9 | 10 | execute_from_command_line(sys.argv) 11 | -------------------------------------------------------------------------------- /service1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "service1", 3 | "version": "1.0.0", 4 | "description": "A very random service", 5 | "main": "app.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Christo Crampton", 10 | "license": "MIT", 11 | "dependencies": { 12 | "express": "^4.13.4" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /service2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "service1", 3 | "version": "1.0.0", 4 | "description": "A very random service", 5 | "main": "app.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Christo Crampton", 10 | "license": "MIT", 11 | "dependencies": { 12 | "express": "^4.13.4" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /userservice/userservice/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for userservice project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "userservice.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /register.sh: -------------------------------------------------------------------------------- 1 | curl -X POST \ 2 | --url http://$1:8001/apis/ \ 3 | --data "name=service1" \ 4 | --data "upstream_url=http://$1:8003" \ 5 | --data "request_host=service1.com" \ 6 | --data "request_path=/service1" \ 7 | --data "strip_request_path=true" 8 | 9 | curl -X POST \ 10 | --url http://$1:8001/apis/ \ 11 | --data "name=service2" \ 12 | --data "upstream_url=http://$1:8004" \ 13 | --data "request_host=service2.com" \ 14 | --data "request_path=/service2" \ 15 | --data "strip_request_path=true" 16 | -------------------------------------------------------------------------------- /userservice/oauth/forms.py: -------------------------------------------------------------------------------- 1 | from django import forms 2 | from oauth import kong 3 | 4 | class ClientApplicationForm(forms.Form): 5 | 6 | application_name = forms.CharField(label='Application name', max_length=100) 7 | redirect_uri = forms.CharField(label='Redirect', max_length=100) 8 | 9 | def save(self, consumer_id): 10 | 11 | data = self.cleaned_data 12 | 13 | app_name = data.get("application_name") 14 | redirect_uri = data.get("redirect_uri") 15 | return kong.create_client_application(consumer_id, app_name, redirect_uri) 16 | 17 | -------------------------------------------------------------------------------- /userservice/userservice/urls.py: -------------------------------------------------------------------------------- 1 | """userservice URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/1.9/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.conf.urls import url, include 14 | 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 15 | """ 16 | from django.conf.urls import url, include 17 | from django.contrib import admin 18 | from oauth import views 19 | 20 | urlpatterns = [ 21 | url(r'^oauth/', views.oauth_allow_access, name="oauth"), 22 | url(r'^authorize/', views.perform_oauth), 23 | url(r'^application/', views.create_application), 24 | url('^', include('django.contrib.auth.urls')), 25 | url(r'^admin/', admin.site.urls), 26 | ] 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Christo Crampton 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /userservice/oauth/templates/oauth/oauth.html: -------------------------------------------------------------------------------- 1 | {% extends "oauth/base.html" %} 2 | 3 | {% block 'content' %} 4 | 5 |
24 | Client_id: {{client_id}}
25 | Client_secret: {{client_secret}}
26 |
24 | Your client_id: {{client_id}}
25 | Your client_secret: {{client_secret}}
26 |
{{token_response}}
58 | {% if service_response1.content %}
59 | {{service_response1.content}}
61 | {{service_response2.content}}
63 | {% endif %}
64 |
65 |