Autodesk-Forge / forge-viewhubs-desktop

Autodesk design file explorer for desktop: Demonstrates a desktop application that shows BIM 360 Team, BIM 360 Docs and Fusion Team hubs, which respective Projects, Folders, Items and Versions
MIT License
38 stars 30 forks source link

Error on load #1

Closed sherbertiConstruct closed 5 years ago

sherbertiConstruct commented 7 years ago

After I have successfully logged in I get this error.

System.Exception: 'Cannot call /api/forge/session/isvalid'

augustogoncalves commented 6 years ago

do you have the localhost server running? Note you need to launch both.

AugustinoJ commented 6 years ago

I'm getting the same error (Cannot call /api/forge/session/isvalid). I have tried setting my solution to start both projects and I have right clicked on "cloud" and started an instance, then right clicked on "desktop" and started an instance. Same error each time. I've changed the host to be non secure (http) and that still doesn't work. How do you start the localhost server?

Snipped from my web.config:

Thanks, Joe

AugustinoJ commented 6 years ago

It appears that this line:

        sessionId = Encoding.UTF8.GetString(System.Web.Security.MachineKey.Unprotect(Convert.FromBase64String(sessionId)));

in HeaderUtils.cs is causing the error. sessionId is a string before it runs through here but is an empty string when this line executes. I've tried commenting out this line but then I get a different RESTAPI response error.

Can you please help with this? Thanks, Joe

augustogoncalves commented 6 years ago

Just tried the sample, works fine, I would suggest you clean the MongoDB database, maybe some data is corrupted and causing this. The sessionId enters this method as NULL, then is set to EMPTY, then the correct value from the cookie header.

I have upgraded the package versions, there is a change on how CefSharp handles cookies, see this line.

OMH2Share commented 5 years ago

I have the same problem. The login to Autocad is fine, then it fails on session/isvalid. I have noted that in HeaderUtils.cs, the GetSessionLocalIDs method, the sessionId is NULL, EMPTY and correct value from cookie, however the unencrypt call always sets sessionId back to empty string. Skipping the unencryption still gives the same error

EDIT: I resolved my problem above, it was due to a hardcoded database name in cloud\App_Code\Database.cs. It must match the database name in your MongoDB! I guess you can read it as the last part of the connection string. Now it works perfectly, thanks!

OMH2Share commented 5 years ago

This change will read the database name from the connection string:

        private static IMongoDatabase Database
        {
            get
            {
                //Read database as last item on the connection string
                string[] parts = ConfigVariables.OAUTH_DATABASE.Split('/');
                string db = parts.Last();
                if (_database == null) _database = Client.GetDatabase(db);
                return _database;
            }
        }
augustogoncalves commented 5 years ago

thanks for the suggestion, @OMH2Share, will add that on the code (it's better 😄 )

augustogoncalves commented 5 years ago

fixed

WspDev commented 5 years ago

This seems to be the error I came up against. It was caused by two things:

  1. Dirty database entries added by debugging process.
  2. The MongoDB filter being created, but not actually used.

(The returned database entry was just the first entry found, with an expired DateTime. Getting a refresh token failed as it was for an access token that had long expired. This caused a status 500 return value.)

The fix is to change var docs = await users.FindAsync(new BsonDocument()); to var docs = await users.Find(filter).ToListAsync();

augustogoncalves commented 5 years ago

thanks @WspDev, makes sense

WspDev commented 5 years ago

Thank you @augustogoncalves . Did you intend to await await on the fix?

augustogoncalves commented 5 years ago

such a silly mistake here... thanks! (push the wrong file)