Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: BoxCCGAuth add User and Admin clients factory methods without initial token #883

Merged
merged 6 commits into from
Jan 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions docs/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ var boxConfig = new BoxConfigBuilder("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
.SetEnterpriseId("YOUR_ENTERPRISE_ID")
.Build();
var boxCCG = new BoxCCGAuth(boxConfig);
```

There are two ways to create an admin client, first one used explicit admin token:
JanVargovsky marked this conversation as resolved.
Show resolved Hide resolved
```c#
var adminToken = await boxCCG.AdminTokenAsync(); //valid for 60 minutes so should be cached and re-used
IBoxClient adminClient = boxCCG.AdminClient(adminToken);
adminClient.Auth.SessionAuthenticated += delegate(object o, SessionAuthenticatedEventArgs e)
Expand All @@ -139,8 +143,12 @@ adminClient.Auth.SessionAuthenticated += delegate(object o, SessionAuthenticated
};
```

App auth applications also often have associated App Users, which are
[created and managed directly by the application](https://developer.box.com/en/guides/authentication/user-types/)
Second way leaves token management (caching) to the `Auth`, a new token is retrieved before the first call. Keep in mind that if you create multiple `adminClient` instances, the token won't be shared, it is expected that the `adminClient` instance is reused.
```c#
IBoxClient adminClient = boxCCG.AdminClient();
```

App auth applications also often have associated [App Users](https://developer.box.com/guides/getting-started/user-types/app-users/), which are created and managed directly by the application
— they do not have normal login credentials, and can only be accessed through
the Box API by the application that created them. You may authenticate as the
Service Account to provision and manage users, or as an individual app user to
Expand All @@ -155,6 +163,10 @@ instance as in the above examples, similarly to creating a Service Account clien
var boxConfig = new BoxConfigBuilder("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
.Build();
var boxCCG = new BoxCCGAuth(boxConfig);
```

Variant with explicit initial token:
```c#
var userToken = await boxCCG.UserTokenAsync("USER_ID"); //valid for 60 minutes so should be cached and re-used
IBoxClient userClient = boxCCG.UserClient(userToken, "USER_ID");
userClient.Auth.SessionAuthenticated += delegate(object o, SessionAuthenticatedEventArgs e)
Expand All @@ -163,6 +175,10 @@ userClient.Auth.SessionAuthenticated += delegate(object o, SessionAuthenticatedE
// cache the new access token
};
```
Variant without initial token:
```c#
IBoxClient userClient = boxCCG.UserClient("USER_ID");
```

### Traditional 3-Legged OAuth2

Expand Down