# coding: utf-8
from openprocurement.auth.provider_app import oauth_provider
from redis import Redis
import openprocurement.auth.models
import openprocurement.auth.views


def make_oath_provider_app(
        global_conf,
        redis='redis://localhost:9002/1',
        secret='abcdfg',
        timezone='Europe/Kiev',
        hash_secret_key='',
        auction_client_id='',
        auction_client_secret=''):

    oauth_provider.debug = True
    oauth_provider.db = Redis.from_url(redis)
    oauth_provider.secret_key = secret
    oauth_provider.hash_secret_key = hash_secret_key

    if not openprocurement.auth.models.Client.get_from_db(client_id=auction_client_id):
        client = openprocurement.auth.models.Client(**
            {'client_id': auction_client_id,
             'client_secret': auction_client_secret,
             '_redirect_uris':' '.join([
                'http:\/\/localhost:.*',
                '(http|https):\/\/[\w\-_]+\.office\.quintagroup\.com.*',
                '(http|https):\/\/[\w\-_]+\.openprocurement\.org\.*',
            ]),
            '_default_scopes':'email'}
        )
        openprocurement.auth.models.Client.save_to_db(client)
    return oauth_provider

@@ -722,10 +722,8 @@
 ent(
-**
 %0A   
@@ -735,10 +735,8 @@
     
-%7B'
 clie
@@ -740,19 +740,17 @@
 lient_id
-': 
+=
 auction_
@@ -772,18 +772,16 @@
         
- '
 client_s
@@ -789,11 +789,9 @@
 cret
-': 
+=
 auct
@@ -821,18 +821,16 @@
         
- '
 _redirec
@@ -835,18 +835,17 @@
 ect_uris
-':
+=
 ' '.join
@@ -845,17 +845,16 @@
  '.join(
-%5B
 %0A       
@@ -862,16 +862,17 @@
         
+%5B
 'http:%5C/
@@ -884,24 +884,25 @@
 alhost:.*',%0A
+ 
             
@@ -970,32 +970,33 @@
                 
+ 
 '(http%7Chttps):%5C/
@@ -1031,17 +1031,17 @@
 .org%5C.*'
-,
+%5D
 %0A       
@@ -1045,17 +1045,16 @@
         
-%5D
 ),%0A     
@@ -1060,17 +1060,16 @@
         
-'
 _default
@@ -1079,18 +1079,16 @@
 opes
-':
+=
 'email'
-%7D
 %0A   

Improve auction client creation