OfficeDev / office-js-helpers

[ARCHIVED] A collection of helpers to simplify development of Office Add-ins & Microsoft Teams Tabs
MIT License
126 stars 56 forks source link

Getting different Office API client ID in the same client. #59

Closed chilejiang1024 closed 6 years ago

chilejiang1024 commented 6 years ago

I get two different IDs in the same client.

And it was with different domains.

With one domain, I got one ID.

I wonder is there something to do with the server when generating IDs?

And how it effects.

WrathOfZombies commented 6 years ago

Could you tell me what is the Office API client ID as I am not quite sure about it?

chilejiang1024 commented 6 years ago

Like this one.

qq 20171130092507

And I use these codes to get it.

var authenticator = new OfficeHelpers.Authenticator();
var clientId = authenticator.endpoints._storage.getItem('Office API client');
WrathOfZombies commented 6 years ago

@Zlatkovsky any thoughts on this?

Zlatkovsky commented 6 years ago

Where does this "Office API Client" ID come from in the first place, though?

If you think it's a bug with Office.js, I recommend you file it under "https://github.com/OfficeDev/office-js/issues" and/or ask a question on StackOverflow tagged with "office-js". A bit more context might help as well (e.g., what host app are you running this from; what version; etc.).

chilejiang1024 commented 6 years ago

Thanks for recommend. I asked a question like this one on StackOverflow some days ago, but it got down vote, and an answer asked me to read the doc in here, I already read it times months ago. No where has infomation about this ID. So I deleted the question, and came here.

Things seems to be more conplex than I thought. A bug, I do not think it is. Already known this ID will be different with different domains.

more details:
1 office.helper.js 
   version:0.6.5 got from [unpkg](https://unpkg.com/@microsoft/office-js-helpers@0.6.5/dist/office.helpers.min.js)
2 office.js
   version:16.01 got from VS2017
3 OS
   windows 10 64 bits
3 Word 2016 with the lastest update

Just want to be sure about some points: 1 Will it exists in the later versions? 2 Is it only effected by the Word app and the domain that the word add-in under.

Thanks again.

WrathOfZombies commented 6 years ago

@chilejiang1024 Thanks for explaining. However I am still unable to see what the bug is. Even if they are different IDs, I am not sure what you are trying to achieve using this ID.

@Zlatkovsky I think I managed to find where this item is being set and it is not in OfficeHelpers but in Word.js (https://github.com/OfficeDev/office-js/blob/release/dist/word-win32-16.00.debug.js#L3740)

chilejiang1024 commented 6 years ago

Thanks for helping!

I don't think it is a bug. I'm sorry for making you guys thought it is. And I know here is not the right position to ask this question. But StackOverflow gave me nothing but some down votes. Sorry for the inconvenience.

What I want is that once users login in word add-in, then he/she won't need to login again when he/she open another word in he/she's pc. So I need to know whether the requests come from the same pc's word. Then I found this ID.

WrathOfZombies commented 6 years ago

Got it. That makes sense. Let me answer it in 2 scenarios.

Assuming that the user launches another Word/Excel on the same machine that he/she's authenticated already then you don't have to do much. All you need to do is call:

var authenticator = new OfficeHelpers.Authenticator();
authenticator.authenticate(OfficeHelpers.DefaultEndpoints.Microsoft).then(token => {
    // the token that you receive here can either be a renewed token or a previously cached one.
});

// If you want to do a token renewal without showing a dialog, Microsoft AD supports iframe based 
// renewal. In which case you can do this:
var token = authenticator. tokens.get(OfficeHelpers.DefaultEndpoints.Microsoft);
// check the expires_in field to determine if the token is expired and then proceed to renew the token.

If it is on a different machine then you need to have server side capabilities to transfer the token between sessions. You can also use the microsoft graph to "roam" the settings.