<p>I'm running a simple flask app in a Kubernettes pod using the basic login sample provided by MS.  Locally it works great.  But once deployed the session[''state'] variable seems to get dropped preventing the login from completing.  Below is my config:</p>

<pre><code>CLIENT_ID = os.getenv('AZURE_CLIENT_ID')
CLIENT_SECRET = os.getenv('AZURE_CLIENT_SECRET')
# production redriect uri
REDIRECT_URI = 'https://agent-workstation-service-manager- 
                   development.app.k8s.nonprod.aws.lmig.com/login/authorized'
# local dev redirect uri
# REDIRECT_URI = 'http://localhost:5000/login/authorized'
AUTHORITY_URL = 'https://login.microsoftonline.com/my_companies_code'
AUTH_ENDPOINT = '/oauth2/v2.0/authorize'
TOKEN_ENDPOINT = '/oauth2/v2.0/token'
RESOURCE = 'https://graph.microsoft.com/'
API_VERSION = 'v1.0'
SCOPES = ['User.Read']
</code></pre>

<p>then the code to call it</p>

<pre><code>@app.route('/login')
def login():
   """Prompt user to authenticate."""
   session['state'] = str(uuid.uuid4())
   return MSGRAPH.authorize(callback=azure.REDIRECT_URI, state=session['state'])

@app.route('/login/authorized')
def authorized():
   """Handler for the application's Redirect Uri."""
   if str(session['state']) != str(request.args['state']):
       raise Exception('state returned to redirect URL does not match!')
   response = MSGRAPH.authorized_response()
   session['access_token'] = response['access_token']
   return redirect('/graphcall')
</code></pre>

<p>my reply_URLs from the azure client set up point to both locations, but why does it drop the session variable when it gets deployed?<br>
Keyerror: 'state' on the line that starts with: if str(session['state'].....</p>

<p>my req.txt file: </p>

<pre><code>Flask==1.1.1
flask-wtf==0.14.2
ldap3==2.6.1
pyodbc==4.0.28
flake8==3.7.9
pytest
WMI==1.4.9
requests==2.22.0
werkzeug==0.16.0
pyyaml==5.2
python-dateutil==2.8.1
oauthlib==2.0.7
Flask-OAuthlib==0.9.5
gunicorn==20.0.4
</code></pre>

Melaa
<p>Session affinity is the answer to this.  Reduced to one pod and it works great.  </p>
