-
Notifications
You must be signed in to change notification settings - Fork 163
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
Server Auth with CCG - initial setup for DI container registration #879
Comments
This makes sense and would make it much easier to create the client synchronously without explicitly calling for token. Just so you know, contributions to this repo are always welcome! For a bit hacky workaround, you could try passing a "fake" or expired token (not a null or empty one as the format should be a proper one!) to the |
Does the
Yes, the SDK can be used to automate things like uploading files so that you don't have to do it through the Box UI. Files uploaded via the SDK should be visible on the site (when appropriate permissions are given etc.). |
Seems like service account ID is just for the UI - for the invite to a folder In the code, I needed to use admin token/client and final result looks as expected now. final code is this: var boxConfig = new BoxConfigBuilder(clientId, clientSecret)
.SetEnterpriseId("<enterprise id>")
.Build();
var boxCCG = new BoxCCGAuth(boxConfig);
var client = boxCCG.AdminClient("fake");
client.Auth.SessionAuthenticated += OnSessionAuthenticated; as I'm rereading the documentation, it was my misunderstanding. However, I'd like to create a PR to make the token optional or totally remove it since it can be refreshed internally, which option do you like more? |
I'm glad the problem has been resolved! I think the preferred way would be to make the token optional to maintain backwards compatibility if possible and don't change this behavior for existing clients. |
Description of the Issue
The code provided in the documentation example is working fine but most modern applications use DI with container registrations that are synchronous. This PR added support for the CCG auth but requires a user token that is available via API call only and this is the root of the issue unless you do the API call to obtain a user token in a synchronous way, there is no way of registering e.g.
IBoxClient
into a container, so you have to wrap it into an async factory method.Another gotcha is the token refresh via
event
, even if would wrapIBoxClient
into an async factory method, register a method to theIBoxClient.Auth.SessionAuthenticated
event that handles the token refresh (token caching), do some API calls (logic), I should unregister the method to avoid leaks.Steps to Reproduce
refactored code with token caching and exposing
IBoxClient
via the async factory methodExpected Behavior
Ability to instantiate
IBoxClient
without initialuser id => user token
exchange.Versions Used
.Net SDK: 4.6.0
The text was updated successfully, but these errors were encountered: