Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit c720025

Browse files
fix NRE in demo client
1 parent f76d7fe commit c720025

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

clients/ConsoleClientWithBrowserAndDPoP/Program.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static async Task Main()
2525
Console.WriteLine("| Sign in with OIDC |");
2626
Console.WriteLine("+-----------------------+");
2727
Console.WriteLine("");
28-
Console.WriteLine("Press any key to sign in...");
28+
Console.WriteLine("Press any key to start...");
2929
Console.ReadKey();
3030

3131
await SignIn();
@@ -36,6 +36,7 @@ private static async Task SignIn()
3636
var browser = new SystemBrowser();
3737
string redirectUri = string.Format($"http://127.0.0.1:{browser.Port}");
3838

39+
// create or retrieve stored proof key
3940
var proofKey = GetProofKey();
4041

4142
var options = new OidcClientOptions
@@ -63,6 +64,8 @@ private static async Task SignIn()
6364
LoginResult result = null;
6465
if (File.Exists("refresh_token"))
6566
{
67+
Console.WriteLine("using stored refresh token");
68+
6669
var refreshToken = File.ReadAllText("refresh_token");
6770
var handler = _oidcClient.CreateDPoPHandler(proofKey, refreshToken);
6871

@@ -76,6 +79,8 @@ private static async Task SignIn()
7679
else
7780
{
7881
result = await _oidcClient.LoginAsync(new LoginRequest());
82+
83+
Console.WriteLine("store refresh token");
7984
File.WriteAllText("refresh_token", result.TokenResponse.RefreshToken);
8085

8186
_apiClient = new HttpClient(result.RefreshTokenHandler)
@@ -94,16 +99,20 @@ private static string GetProofKey()
9499
{
95100
if (File.Exists("proofkey"))
96101
{
102+
Console.WriteLine("using stored proof key");
97103
return File.ReadAllText("proofkey");
98104
}
99105

106+
Console.WriteLine("creating and storing proof key");
100107
var proofKey = JsonWebKeys.CreateRsaJson();
101108
File.WriteAllText("proofkey", proofKey);
102109
return proofKey;
103110
}
104111

105112
private static void ShowResult(LoginResult result)
106113
{
114+
if (result == null) return;
115+
107116
if (result.IsError)
108117
{
109118
Console.WriteLine("\n\nError:\n{0}", result.Error);

0 commit comments

Comments
 (0)