##// END OF EJS Templates
authomatic: should not be a global object anymore
ergo -
Show More
@@ -29,8 +29,6 b' from pkg_resources import iter_entry_points'
29 import appenlight.lib.jinja2_filters as jinja2_filters
29 import appenlight.lib.jinja2_filters as jinja2_filters
30 import appenlight.lib.encryption as encryption
30 import appenlight.lib.encryption as encryption
31
31
32 from authomatic.providers import oauth2, oauth1
33 from authomatic import Authomatic
34 from pyramid.config import PHASE3_CONFIG
32 from pyramid.config import PHASE3_CONFIG
35 from pyramid.authentication import AuthTktAuthenticationPolicy
33 from pyramid.authentication import AuthTktAuthenticationPolicy
36 from pyramid.authorization import ACLAuthorizationPolicy
34 from pyramid.authorization import ACLAuthorizationPolicy
@@ -125,6 +123,8 b' def main(global_config, **settings):'
125 'unsafe_json_body', reify=True)
123 'unsafe_json_body', reify=True)
126 config.add_request_method('appenlight.lib.request.add_flash_to_headers',
124 config.add_request_method('appenlight.lib.request.add_flash_to_headers',
127 'add_flash_to_headers')
125 'add_flash_to_headers')
126 config.add_request_method('appenlight.lib.request.get_authomatic',
127 'authomatic', reify=True)
128
128
129 config.include('pyramid_redis_sessions')
129 config.include('pyramid_redis_sessions')
130 config.include('pyramid_tm')
130 config.include('pyramid_tm')
@@ -181,49 +181,6 b' def main(global_config, **settings):'
181 'appenlight.scripts',
181 'appenlight.scripts',
182 'appenlight.tests'])
182 'appenlight.tests'])
183
183
184 # authomatic social auth
185 authomatic_conf = {
186 # callback http://yourapp.com/social_auth/twitter
187 'twitter': {
188 'class_': oauth1.Twitter,
189 'consumer_key': settings.get('authomatic.pr.twitter.key', 'X'),
190 'consumer_secret': settings.get('authomatic.pr.twitter.secret',
191 'X'),
192 },
193 # callback http://yourapp.com/social_auth/facebook
194 'facebook': {
195 'class_': oauth2.Facebook,
196 'consumer_key': settings.get('authomatic.pr.facebook.app_id', 'X'),
197 'consumer_secret': settings.get('authomatic.pr.facebook.secret',
198 'X'),
199 'scope': ['email'],
200 },
201 # callback http://yourapp.com/social_auth/google
202 'google': {
203 'class_': oauth2.Google,
204 'consumer_key': settings.get('authomatic.pr.google.key', 'X'),
205 'consumer_secret': settings.get(
206 'authomatic.pr.google.secret', 'X'),
207 'scope': ['profile', 'email'],
208 },
209 'github': {
210 'class_': oauth2.GitHub,
211 'consumer_key': settings.get('authomatic.pr.github.key', 'X'),
212 'consumer_secret': settings.get(
213 'authomatic.pr.github.secret', 'X'),
214 'scope': ['repo', 'public_repo', 'user:email'],
215 'access_headers': {'User-Agent': 'AppEnlight'},
216 },
217 'bitbucket': {
218 'class_': oauth1.Bitbucket,
219 'consumer_key': settings.get('authomatic.pr.bitbucket.key', 'X'),
220 'consumer_secret': settings.get(
221 'authomatic.pr.bitbucket.secret', 'X')
222 }
223 }
224 config.registry.authomatic = Authomatic(
225 config=authomatic_conf, secret=settings['authomatic.secret'])
226
227 # resource type information
184 # resource type information
228 config.registry.resource_types = ['resource', 'application']
185 config.registry.resource_types = ['resource', 'application']
229
186
@@ -19,9 +19,14 b''
19 # services, and proprietary license terms, please see
19 # services, and proprietary license terms, please see
20 # https://rhodecode.com/licenses/
20 # https://rhodecode.com/licenses/
21
21
22 import appenlight.lib.helpers as helpers
23 import json
22 import json
23
24 from pyramid.security import unauthenticated_userid
24 from pyramid.security import unauthenticated_userid
25
26 import appenlight.lib.helpers as helpers
27
28 from authomatic.providers import oauth2, oauth1
29 from authomatic import Authomatic
25 from appenlight.models.user import User
30 from appenlight.models.user import User
26
31
27
32
@@ -87,3 +92,49 b' def add_flash_to_headers(request, clear=True):'
87 flash_msgs = helpers.get_type_formatted_flash(request)
92 flash_msgs = helpers.get_type_formatted_flash(request)
88 request.response.headers['x-flash-messages'] = json.dumps(flash_msgs)
93 request.response.headers['x-flash-messages'] = json.dumps(flash_msgs)
89 helpers.clear_flash(request)
94 helpers.clear_flash(request)
95
96
97 def get_authomatic(request):
98 settings = request.registry.settings
99 # authomatic social auth
100 authomatic_conf = {
101 # callback http://yourapp.com/social_auth/twitter
102 'twitter': {
103 'class_': oauth1.Twitter,
104 'consumer_key': settings.get('authomatic.pr.twitter.key', ''),
105 'consumer_secret': settings.get('authomatic.pr.twitter.secret',
106 ''),
107 },
108 # callback http://yourapp.com/social_auth/facebook
109 'facebook': {
110 'class_': oauth2.Facebook,
111 'consumer_key': settings.get('authomatic.pr.facebook.app_id', 'X'),
112 'consumer_secret': settings.get('authomatic.pr.facebook.secret',
113 ''),
114 'scope': ['email'],
115 },
116 # callback http://yourapp.com/social_auth/google
117 'google': {
118 'class_': oauth2.Google,
119 'consumer_key': settings.get('authomatic.pr.google.key', ''),
120 'consumer_secret': settings.get(
121 'authomatic.pr.google.secret', ''),
122 'scope': ['profile', 'email'],
123 },
124 'github': {
125 'class_': oauth2.GitHub,
126 'consumer_key': settings.get('authomatic.pr.github.key', ''),
127 'consumer_secret': settings.get(
128 'authomatic.pr.github.secret', ''),
129 'scope': ['repo', 'public_repo', 'user:email'],
130 'access_headers': {'User-Agent': 'AppEnlight'},
131 },
132 'bitbucket': {
133 'class_': oauth1.Bitbucket,
134 'consumer_key': settings.get('authomatic.pr.bitbucket.key', ''),
135 'consumer_secret': settings.get(
136 'authomatic.pr.bitbucket.secret', '')
137 }
138 }
139 return Authomatic(
140 config=authomatic_conf, secret=settings['authomatic.secret'])
@@ -512,7 +512,7 b' def social_auth(request):'
512
512
513 # Start the login procedure.
513 # Start the login procedure.
514 adapter = WebObAdapter(request, request.response)
514 adapter = WebObAdapter(request, request.response)
515 result = request.registry.authomatic.login(adapter, provider_name)
515 result = request.authomatic.login(adapter, provider_name)
516 if result:
516 if result:
517 if result.error:
517 if result.error:
518 return handle_auth_error(request, result)
518 return handle_auth_error(request, result)
General Comments 0
You need to be logged in to leave comments. Login now