@@ -20,41 +20,65 @@ This library provides OAuth2/PKCE authentication to Safeguard by allowing applic
2020
2121## Usage Example
2222
23+ The library drives the OAuth2/PKCE authorization-code flow internally by
24+ posting directly to the rSTS login endpoints — no browser, no TCP listener,
25+ and no caller-supplied authorization code are required. The caller supplies
26+ the appliance address and credentials; everything else (code verifier/
27+ challenge generation, authorization, code redemption, token exchange) is
28+ handled by ` Connect ` / ` ConnectAsync ` .
29+
2330``` csharp
31+ using System .Security ;
32+ using OneIdentity .SafeguardDotNet ;
2433using OneIdentity .SafeguardDotNet .PkceNoninteractiveLogin ;
2534
26- // Step 1: Generate PKCE parameters
27- var codeVerifier = PkceNoninteractiveLogin .GenerateCodeVerifier ();
28- var codeChallenge = PkceNoninteractiveLogin .GenerateCodeChallenge (codeVerifier );
35+ SecureString password = GetPasswordSecurely ();
36+
37+ using var connection = PkceNoninteractiveLogin .Connect (
38+ appliance : " safeguard.example.com" ,
39+ provider : " local" ,
40+ username : " Admin" ,
41+ password : password ,
42+ ignoreSsl : false );
2943
30- // Step 2: Build authorization URL
31- var authUrl = PkceNoninteractiveLogin .BuildAuthorizationUrl (
32- " safeguard.example.com" ,
33- codeChallenge ,
34- username : " admin" );
44+ var me = connection .InvokeMethod (Service .Core , Method .Get , " Me" );
45+ ```
3546
36- // Step 3: Your custom code to authenticate and obtain authorization code
37- // (e.g., using Selenium, Playwright, or other automation tools)
38- var authorizationCode = YourCustomAuthenticationMethod (authUrl );
47+ ### Multi-factor authentication
3948
40- // Step 4: Connect to Safeguard
41- var connection = PkceNoninteractiveLogin .Connect (
42- " safeguard.example.com" ,
43- authorizationCode ,
44- codeVerifier );
49+ If the identity provider requires a second factor (TOTP, RADIUS, etc.), pass
50+ the one-time code as ` secondaryPassword ` :
51+
52+ ``` csharp
53+ SecureString password = GetPasswordSecurely ();
54+ SecureString totp = GetOneTimeCodeSecurely ();
4555
46- // Step 5: Use the connection
47- var userData = connection .InvokeMethod (Service .Core , Method .Get , " Me" );
56+ using var connection = PkceNoninteractiveLogin .Connect (
57+ " safeguard.example.com" , " local" , " Admin" , password , totp );
58+ ```
59+
60+ ### Async with cancellation
61+
62+ ``` csharp
63+ using var cts = new CancellationTokenSource (TimeSpan .FromSeconds (60 ));
64+ SecureString password = GetPasswordSecurely ();
65+
66+ using var connection = await PkceNoninteractiveLogin .ConnectAsync (
67+ " safeguard.example.com" , " local" , " Admin" , password ,
68+ secondaryPassword : null ,
69+ apiVersion : Safeguard .DefaultApiVersion ,
70+ ignoreSsl : false ,
71+ cancellationToken : cts .Token );
4872```
4973
5074## Comparison with BrowserLogin
5175
5276| Feature | BrowserLogin | PkceNoninteractiveLogin |
5377| ---------| -------------| -------------------------|
54- | Browser Launch | Automatic | Manual (caller controlled) |
55- | TCP Listener | Built-in | Not included |
56- | Authorization Code | Captured automatically | Must be obtained by caller |
57- | Use Case | Interactive desktop apps | Automated testing, custom flows |
78+ | Browser Launch | Automatic | None — flow is driven over HTTP |
79+ | TCP Listener | Built-in | Not needed |
80+ | Credentials | Entered in browser by user | Supplied by caller (username/password, optional MFA code) |
81+ | Use Case | Interactive desktop apps | Automated testing, CI/CD, headless integrations |
5882
5983## Dependencies
6084
0 commit comments