Python desktop application - close browser in OAuth2 PKCE flow

530 views Asked by At

I have implemented OAuth2 PKCE flow with Okta using Python. It is a desktop application. I am using custom URL scheme as redirect URL to receive authorization code. Everything works fine and browser opens application when it sees custom URL scheme in redirect URL but the browser remains open and shows in progress Okta sign in image. What can be done to either close the browser or show appropriate message in browser?

1

There are 1 answers

0
Gary Archer On BEST ANSWER

It is a tricky flow and it is difficult to get this perfect, though returning to a web page after login rather than directly to the app will give you greater control:

DEFAULT OPTION

Use a redirect URI such as x-mycompany-desktopapp:/callback, which is invoked automatically, but this results in a leftover / confusing browser page, as you are finding.

INTERSTITIAL PAGE OPTION

Update the redirect URI to a value such as this, which is a web page you need to host:

If you do a 'View Source' on the above page you will see that it invokes the custom URI scheme when a Continue button is clicked. This at least gives you control over the post login behaviour and messaging.

FURTHER INFO

My blog post has further details and a NodeJS desktop code sample you can run.