Request the authorization code

This code creates a new instance of the OAuth2Client passing the authorization end point.

Additionally, it leverages the OAuth2Client to construct the correct URL to obtain the authorization code. The constructed URL must be presented to a user through a user-agent, for example, an embedded browser in the client.

The user must authenticate and authorize by providing the tokens to the thick client. LoginWebView is a window that has a WebBrowser. This navigates the user to the specified URI, checks the different URLs that the user is redirected to, and detects when the user navigates to the RedirectUri.

var state = Guid.NewGuid().ToString("N");
var nonce = Guid.NewGuid().ToString("N");
var client = new OAuth2Client(new Uri(OAuth2AuthorizationEndpoint));
var startUrl = client.CreateCodeFlowUrl(
clientId: ClientId,
redirectUri: RedirectUri,
state: state,
nonce: nonce);
LoginWebView webView = new LoginWebView();
webView.Owner = this;
webView.Done += _login_Done;
webView.Show();
webView.Start(new Uri(startUrl), new Uri(RedirectUri));