Home > Software engineering >  Python request.url not returning full url that is shown in the browser
Python request.url not returning full url that is shown in the browser

Time:10-12

I am implementing Signin via Microsoft Auth in my App. When I go to authorization url and provide my credentials, the app redirects to my redirect uri. In the browser I am getting this url "http://localhost:5000/app/microsoft_signin/callback#code=M.R3_BAY.bc055b02-10a5-be57-8933-191cbb5d6b1d&state=12345" but when I try to get this url using request.url, I am getting only this part of the url "http://localhost:5000/app/microsoft_signin/callback".

Here is my code:

app.route("/app/microsoft_signin",methods=['GET','POST'])
def microsoft_signin_():

authorization_url = f'{MICROSOFT_CONFIG["MICROSOFT_AUTHORIZATION_URL"]}?client_id={MICROSOFT_CONFIG["MICROSOFT_CLIENT_ID"]}&response_type=code&redirect_uri={MICROSOFT_CONFIG["MICROSOFT_REDIRECT_URI"]}&response_mode=fragment&scope={MICROSOFT_CONFIG["MICROSOFT_SCOPE"]}&state=12345'
return redirect(authorization_url) 


@app.route("/app/microsoft_signin/callback",methods=['POST','PUT','GET'])
def microsoft_signin_callback_():

print('!!! CALL BACK HIT SUCCESSFULLY !!!')

print(f'Returned URL is: {request.url}') // http://localhost:5000/app/microsoft_signin/callback

Is there any other way to get this complete url? Also I found something strange with the returned url. Before "code", I am getting # instead of ?, due to which I am unable to get the code using this line code = request.args.get("code")

CodePudding user response:

Replace response_mode=fragment with response_mode=query

  • Related