OAuth-Login mit ETRON onRetail für Apps/Websites
Meiiapp Anbindung
Beispiel in Python
```python
#Beispiel via Python und flask lib
from flask_oauthlib.client import OAuth
app = Flask(__name__)
app.secret_key = CONFIG['app_secret']
oauth = OAuth(app)
# Configere the OAuth 2.0 client
Meiiapp = oauth.remote_app(
'meiiapp',
consumer_key='meiiappkey', #aus oath client config
consumer_secret=CONFIG['wo_das_secret_abgelegt_ist'], #aus oauth client config
request_token_params={
'scope': 'Meiiapp', # Scope ist frei waehlbar
},
base_url='https://KUNDENDOMAIN_ONRETAIL/',
request_token_url=None,
access_token_method='POST',
access_token_url=base_url+'/api/v1/authentication/oauth2/token',
authorize_url=base_url+'/api/v1/authentication/oauth2/authorize',
)
# Beispiel fuer die Login/Logout Routen
@app.before_request
def check_login():
#erlaube localhost ohne auth
if request.host in ['localhost', '127.0.0.1', 'localhost:8000', '127.0.0.1:8000']:
return None
whitelist = ['/logout', '/login', '/authorized', '/static/']
if not any(map(lambda x: request.path.startswith(x), whitelist)):
if 'meiiapp_oauth_token' not in session:
return redirect(url_for('login'))
@app.route('/login')
def login():
return Meiiapp.authorize(callback=url_for('authorized', _external=True, _scheme=_scheme))
@app.route('/logout')
def logout():
session.pop('meiapp_oauth_token', None)
return redirect('/login')
@app.route('/authorized')
def authorized():
response = Meiiapp.authorized_response()
if response is None or response.get('access_token') is None:
return 'Access denied: reason={} error={}'.format(
request.args['error_reason'],
request.args['error_description']
)
# Save the user's access token and other information as needed
session['meiiapp_oauth_token'] = (response['access_token'], '')
# At this point, the user is logged in. Redirect as needed.
return redirect(url_for('meiiapp_homepage'))Last updated


