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

Feature.kotti auth #137

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/kotti_velruse/CHANGES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0.1
---

- Initial version
2 changes: 2 additions & 0 deletions examples/kotti_velruse/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include *.txt *.ini *.cfg *.rst
recursive-include kotti_velruse *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml
43 changes: 43 additions & 0 deletions examples/kotti_velruse/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
For the impatient
-----------------

1. Simply run script run-server.sh

2. Navigate to page /login like the example below:

$ firefox http://localhost:6543/login


Configuration
-------------

1. Please adjust variable *realm* in development.ini.

2. Several providers need to be configured according to your affiliation
keys with providers like Google OAuth2, Twitter, Facebook, etc.

Several providers work out of the box, like Google Hybrid, Yahoo and most
of OpenID providers.


About this example
------------------

This example evolved to a proper plugin, which is available from PyPI at
https://pypi.python.org/pypi/kotti_velruse


Dependencies
------------

This example depends on a modified versions of velruse and openid-selector:

* velruse: https://pypi.python.org/pypi/rgomes_velruse

* openid-selector: https://pypi.python.org/pypi/openid-selector

Sources for these changed sources are available at:

* velruse: https://github.com/frgomes/velruse/tree/feature.kotti_auth

* openid-selector: https://github.com/frgomes/velruse
217 changes: 217 additions & 0 deletions examples/kotti_velruse/development.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
###
# wsgi server configuration
###

[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 6543



[app:kotti_velruse]
use = egg:kotti_velruse

pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en

#pyramid.includes =
# pyramid_debugtoolbar

# By default, the toolbar only appears for clients from IP addresses
# '127.0.0.1' and '::1'.

# you should change this
session.secret=CHANGE-ME





### --------------------------------------------------------------------------
# [dummy] Kotti configuration
# These settings are necessary when testing plugins in isolation.
###

[filter:fanstatic]
use = egg:fanstatic#fanstatic

[pipeline:main]
pipeline = fanstatic
kotti

[app:kotti]
use = egg:kotti

pyramid.reload_templates = true
pyramid.debug_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en

pyramid.includes = pyramid_debugtoolbar
pyramid_tm

sqlalchemy.url = sqlite:///%(here)s/Kotti.db
#mail.default_sender = yourname@yourhost

kotti.site_title = My Kotti site
kotti.secret = qwerty

kotti.configurators = kotti_tinymce.kotti_configure
kotti_velruse.kotti_configure

### --------------------------------------------------------------------------




### --------------------------------------------------------------------------
# velruse configuration
#
# Module velruse.app.includeme looks for entries named "provider." in order
# to discover which providers are configured.
#
# NOTE: these configurations must be inside [app:kotti]
#
###

#---
# Please adjust variable REALM
#
# Make sure that:
#
# 1. your browser is able to resolve the FQDN
# 2. your Kotti server is able to resolve the FQDN
#
#---
realm=http://www.example.com

endpoint = %(realm)s:6543/logged_in
store = memory
# store = redis
# store.host = localhost
# store.port = 6379
# store.db = 0
# store.key_prefix = velruse_ustore

# OpenID
# Despite a single provide.openid is declared, you can specify multiple
# URLs that should be used for connecting to multiple OpenID endpoints.
# See: login.mako for an example of how this can be done
provider.openid.realm=%(realm)s
provider.openid.store=openid.store.memstore:MemoryStore

# Google (this an alias to Google Hybrid, for backward compatibility)
provider.google.realm=%(realm)s
provider.google.consumer_key=CHANGE-ME
provider.google.consumer_secret=CHANGE-ME
provider.google.scope=CHANGE-ME

# Google Hybrid
#provider.google_hybrid.realm=%(realm)s
#provider.google_hybrid.consumer_key=CHANGE-ME
#provider.google_hybrid.consumer_secret=CHANGE-ME
#provider.google_hybrid.scope=CHANGE-ME

# Google OAuth2
provider.google_oauth2.consumer_key=CHANGE-ME
provider.google_oauth2.consumer_secret=CHANGE-ME
provider.google_oauth2.scope=CHANGE-ME

# Yahoo
provider.yahoo.realm=%(realm)s
provider.yahoo.consumer_key=CHANGE-ME
provider.yahoo.consumer_secret=CHANGE-ME

# Live
provider.live.client_id=CHANGE-ME
provider.live.client_secret=CHANGE-ME
provider.live.consumer_key=CHANGE-ME
provider.live.consumer_secret=CHANGE-ME

# Twitter
provider.twitter.consumer_key=CHANGE-ME
provider.twitter.consumer_secret=CHANGE-ME

# Facebook
provider.facebook.app_id=CHANGE-ME
provider.facebook.app_secret=CHANGE-ME
provider.facebook.consumer_key=CHANGE-ME
provider.facebook.consumer_secret=CHANGE-ME
provider.facebook.scope=email,publish_stream,read_stream,create_event,offline_access

# LinkedIn
provider.linkedin.consumer_key=CHANGE-ME
provider.linkedin.consumer_secret=CHANGE-ME

# Github
provider.github.consumer_key=CHANGE-ME
provider.github.consumer_secret=CHANGE-ME
provider.github.scope=CHANGE-ME

# BitBucket
provider.bitbucket.consumer_key=CHANGE-ME
provider.bitbucket.consumer_secret=CHANGE-ME

# MailRU
provider.mailru.app_id=CHANGE-ME
provider.mailru.app_secret=CHANGE-ME
provider.mailru.consumer_key=CHANGE-ME
provider.mailru.consumer_secret=CHANGE-ME

### --------------------------------------------------------------------------




### --------------------------------------------------------------------------
# logging configuration
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html
###

[loggers]
keys = root, kotti, velruse, sqlalchemy

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[logger_kotti]
level = DEBUG
handlers =
qualname = kotti

[logger_velruse]
level = DEBUG
handlers =
qualname = kotti_velruse

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine
# "level = INFO" logs SQL queries.
# "level = DEBUG" logs SQL queries and results.
# "level = WARN" logs neither. (Recommended for production systems.)

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s

### --------------------------------------------------------------------------
12 changes: 12 additions & 0 deletions examples/kotti_velruse/kotti_velruse/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from pyramid.i18n import TranslationStringFactory


log = __import__('logging').getLogger(__name__)


_ = TranslationStringFactory('kotti_velruse')


def kotti_configure(settings):
settings['pyramid.includes'] += ' velruse.app'
settings['pyramid.includes'] += ' kotti_velruse.views'
50 changes: 50 additions & 0 deletions examples/kotti_velruse/kotti_velruse/templates/login.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>${project} :: Login</title>
<!-- Simple OpenID Selector -->
<link type="text/css" rel="stylesheet" href="css/openid.css" />
<script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="js/openid-jquery.js"></script>
<script type="text/javascript" src="js/openid-en.js"></script>
<script type="text/javascript">
$(document).ready(function() {
openid.init('openid_identifier');
openid.setDemoMode(false); //Stops form submission for client javascript-only test purposes
});
</script>
<!-- /Simple OpenID Selector -->
<style type="text/css">
/* Basic page formatting */
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
</style>
</head>

<body>
<h2>Login to ${project}</h2>
<!-- Simple OpenID Selector -->
<form action="${login_url}" method="get" id="openid_form">
<input type="hidden" id="action" name="action" value="verify" />
<input type="hidden" id="method" name="method" value="unknown" />
<fieldset>
<legend>Sign-in</legend>
<div id="openid_choice">
<p>Please click your account provider:</p>
<div id="openid_btns"></div>
</div>
<div id="openid_input_area">
<input id="openid_identifier" name="openid_identifier" type="text" value="http://" />
<input id="openid_submit" type="submit" value="Sign-In"/>
</div>
</fieldset>
</form>
<!-- /Simple OpenID Selector -->
<p><small>OpenID allows you to log-on to many different websites using a single identity.<br/>
Find out <a href="http://openid.net/what/">more about OpenID</a> and
<a href="http://openid.net/get/">how to get an OpenID enabled account</a>.</small></p>
</body>
</html>
14 changes: 14 additions & 0 deletions examples/kotti_velruse/kotti_velruse/templates/result.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Result Page</title>
</head>
<body>

<pre id="result">
${ result|n }
</pre>

</body>
</html>
20 changes: 20 additions & 0 deletions examples/kotti_velruse/kotti_velruse/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import unittest

from pyramid import testing

import velruse.app


class ViewTests(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()

def tearDown(self):
testing.tearDown()

def test_login_view(self):
from .views import login_view
request = testing.DummyRequest()
providers = velruse.app.find_providers(request.registry.settings)
info = login_view(request)
self.assertEqual(info['providers'], providers)
Loading