Skip to content

Conversation

@rayluo
Copy link
Contributor

@rayluo rayluo commented Nov 17, 2020

This PR simplifies the current web app sample based on a new higher-level acquire_token_by_auth_code_flow() API, which will be available in MSAL 1.7.0 (coming soon).

On surface, this PR shrinks the 100+ lines code base by just 6 lines. The real difference is the reduction of cognitive load in the major function authorized(), while providing more functionality (the PKCE protection), AUTOMATICALLY. The table below is a comparison.

Before this PR After this PR
OAuth2 Concepts exposed 2 (state and code) 0
if statements 4 1 (plus one more exception handling)
exits 4 code paths 2

Other than that, the functionality of this sample remains versatile: it supports authentication, web API call, B2C authentication, B2C web API call, B2C edit profile, B2C reset password, and it will automatically pick up the PKCE feature provided by MSAL 1.7.

PR reviews are welcome, although this PR will not currently work, until MSAL 1.7 being released.

Copy link
Contributor

@idg-sam idg-sam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't run it yet, but upon a quick review of the code it looks great. Only suggestion is to add a state arg to the build_auth_code_flow (have added the code suggestion)

👍 👍 👍

session["user"] = result.get("id_token_claims")
_save_cache(cache)
except ValueError: # Usually caused by CSRF
pass # Simply ignore them

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rayluo could you explain why this is ok to ignore, and would upgrading the ms-identity-python-samples-common repo to the new scheme help mitigate my issue Azure-Samples/ms-identity-python-samples-common#4 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this particular implementation, ignoring the ValueError here would let the next line run, which is to go back to the index page at a not-yet-signed-in state, rather than an error page. The current approach is our desirable user experience to handle the state mismatch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants