Skip to content

Commit 4b84873

Browse files
authored
docs: correct README API examples to match shipped code (#235)
* docs: correct README API examples to match shipped code * ci: also exclude root *.md from CI/PR triggers * Revert "ci: also exclude root *.md from CI/PR triggers" This reverts commit 77a69da.
1 parent e67b9f7 commit 4b84873

5 files changed

Lines changed: 54 additions & 29 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ var userJson = connection.InvokeMethod(Service.Core, Method.Post, "Users",
409409
}));
410410
var userObj = JsonConvert.DeserializeAnonymousType(userJson, new { Id = 0 });
411411
connection.InvokeMethod(Service.Core, Method.Put, $"Users/{userObj.Id}/Password",
412-
JsonConvert.SerializeObject("MyNewUser123");
412+
JsonConvert.SerializeObject("MyNewUser123"));
413413
```
414414

415415
## Using SafeguardDotNet from a New Visual Studio Code Project

SafeguardDotNet.BrowserLogin/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,24 @@ using OneIdentity.SafeguardDotNet;
4141
using OneIdentity.SafeguardDotNet.BrowserLogin;
4242

4343
// Authenticate user via browser
44-
var connection = Safeguard.ConnectBrowser("safeguard.company.com");
44+
var connection = DefaultBrowserLogin.Connect("safeguard.company.com");
4545

4646
// Use the authenticated connection
4747
string userData = connection.InvokeMethod(Service.Core, Method.Get, "Me");
4848
Console.WriteLine($"Logged in as: {userData}");
4949
```
5050

51-
### With Specific Authentication Provider
51+
### Pre-fill the username
5252

5353
```csharp
54-
var connection = DefaultBrowserLogin.Connect("myspp.petrsnd.test", ignoreSsl: false);
54+
var connection = DefaultBrowserLogin.Connect(
55+
"safeguard.company.com", username: "Admin", ignoreSsl: false);
5556
```
5657

5758
### Advanced Options
5859

5960
```csharp
60-
// Configure an alternate listing port (default: 8400 [same as Microsoft])
61+
// Configure an alternate listener port (default: 8400)
6162
var connection = DefaultBrowserLogin.Connect("safeguard.company.com", port: 8080);
6263
```
6364

SafeguardDotNet.DeviceCodeLogin/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ using var connection = await DeviceCodeLogin.ConnectAsync(
7575
| Credentials in Code | No | Yes (username/password) | No |
7676
| SSO/MFA Support | Yes | Limited | Yes |
7777
| Headless Compatible | No | Yes | Yes |
78-
| Async API | No | No | Yes |
78+
| Async API | Yes | Yes | Yes |
7979
| Use Case | Desktop apps | Automation with known creds | Headless with user auth |
8080

8181
## Configuration

SafeguardDotNet.GuiLogin/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Console.WriteLine($"Logged in as: {userData}");
5858

5959
## How It Works
6060

61-
1. **Show Dialog** - Application calls `Safeguard.ConnectGui()` which displays WinForms dialog
61+
1. **Show Dialog** - Application calls `LoginWindow.Connect()` which displays a WinForms dialog
6262
2. **Embedded Browser** - Dialog contains WebView2 control showing Safeguard login page
6363
3. **User Authenticates** - User logs in through their chosen identity provider
6464
4. **Capture Token** - Dialog captures OAuth token from redirect

SafeguardDotNet.PkceNoninteractiveLogin/README.md

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
2433
using 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

Comments
 (0)