> For the complete documentation index, see [llms.txt](https://helpcenter.etron.info/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://helpcenter.etron.info/schnelles-wissen/oauth-login-mit-etron-onretail-fur-apps-websites-meiiapp.md).

# OAuth-Login mit ETRON onRetail für Apps/Websites (meiiapp)

Meiiapp Anbindung

{% hint style="success" %}
*Modul: REST API*
{% endhint %}

Diese Anleitung beschreibt die Integration des OAuth 2.0 Logins von ETRON onRetail in externe Webanwendungen oder Apps. Dies ermöglicht die Anmeldung von Benutzerkonten aus ETRON onRetail in Drittanwendungen (z. B. progressive Web-Apps, Kundenzugänge oder Migrationsportale).

{% stepper %}
{% step %}

### Einrichtung eines OAuth-Clients in ETRON onRetail

1. Anmeldung in der ETRON onRetail Verwaltungsoberfläche
2. Navigieren zu [API & Hooks](/verwaltungsoberflache/api-and-hooks.md).
3. Neuen OAuth-Client anlegen:
   * Name: z. B. *Meiiapp Auth*<br>

     <figure><img src="https://2281246901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlM26Mg6nljOOOe95HyIq%2Fuploads%2F7G9X2yA2K2eXKPqOhXml%2Fimage.png?alt=media&amp;token=3d00145b-f27b-4c6a-911f-3d86a754fce8" alt=""><figcaption></figcaption></figure>
   * **Client-ID** und **Client-Secret** speichern
   * **Redirect URL (Callback-URL)** der Zielanwendung (Partner-App/-Website) eintragen\
     z. B. `https://meii.app/oauth/callback`

     <figure><img src="https://2281246901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlM26Mg6nljOOOe95HyIq%2Fuploads%2FrUSXcSS4bebnd3wruCyy%2Fimage.png?alt=media&amp;token=ba334986-4429-45ab-816c-4b07da0cea9a" alt=""><figcaption></figcaption></figure>

{% endstep %}

{% step %}

## Implementierung des OAuth-Flows in der Drittanwendung

1. **Login-Button**\
   Ein Login-Button in der Drittanwendung leitet zur Authorisierungsseite von ETRON onRetail weiter.

   <figure><img src="https://2281246901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlM26Mg6nljOOOe95HyIq%2Fuploads%2F0y7xuQAKvEwP7gbmNTve%2Fimage.png?alt=media&amp;token=71243946-8040-4521-9908-aae0bdcc2097" alt=""><figcaption></figcaption></figure>
2. **Autorisierungscode**\
   Nach erfolgreichem Login wird der Nutzer zur Callback-URL der Drittanwendung umgeleitet. Ein **Authorization-Code** wird dabei übermittelt.<br>
3. **Access-Token anfordern**\
   Serverseitig oder in der App (z. B. via Secure Storage) wird der Authorization-Code gegen ein **Access-Token** getauscht.
4. **Authentifizierte API-Aufrufe**\
   Alle weiteren API-Aufrufe können mit dem Access-Token über den `Authorization`-Header erfolgen:

<pre class="language-http"><code class="lang-http"><strong>httpKopierenBearbeitenAuthorization: Bearer [ACCESS_TOKEN]
</strong></code></pre>

{% endstep %}
{% endstepper %}

## Beispiel in Python

````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'))
````


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://helpcenter.etron.info/schnelles-wissen/oauth-login-mit-etron-onretail-fur-apps-websites-meiiapp.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
