Urgent : Not able to refresh access and refresh tokens automatically in c#.net
Hi,
I have created a c# console application where I am using box windows SDK in VS 2017 to connect to Box for uploading files to box. I have 2000+ files in database where I am pulling it from database and uploading it to Box one by one. However I could upload 700+ files successfully in 1hr and after 1 hr session gets invalidated even though I am trying to manually update the tokens through code .But the tokens are not getting refreshed and the session gets invalidated.
Below is the code:
string CLIENT_ID = "clientid";
string CLIENT_SECRET = "clientsecret";
string DEV_ACCESS_TOKEN = "accesstoken"; //log into developers.box.com and get this for your registered app; it will last for 60 minutes
string REFRESH_TOKEN = "refreshtoken";
try
{
var config = new BoxConfig(CLIENT_ID, CLIENT_SECRET, new Uri("http://localhost"));
var session = new OAuthSession(DEV_ACCESS_TOKEN, REFRESH_TOKEN, 3600, "bearer");
client = new BoxClient(config, session);
client.Auth.SessionAuthenticated += Auth_SessionAuthenticated;
client.Auth.SessionInvalidated += Auth_SessionInvalidated;
AsyncContext.Run(() => MainAsync());
}
public static void Auth_SessionInvalidated(object sender, EventArgs e)
{
}
public static void Auth_SessionAuthenticated(object sender, SessionAuthenticatedEventArgs e)
{
DEV_ACCESS_TOKEN = e.Session.AccessToken;
REFRESH_TOKEN =e.Session.RefreshToken;
}
-
Are you trying to refresh the Developer Token in this case? That token is for testing only, and cannot be refreshed. In order to stay authenticated for longer than 60 minutes, you will need to properly implement authentication using either standard OAuth2 or JWT server auth, depending on what type of auth you have.
Please sign in to leave a comment.
Comments
1 comment