Skip to content
This repository was archived by the owner on Jun 16, 2025. It is now read-only.

Sample enhancements: Remove token cache file, add properties file#7

Merged
Avery-Dunn merged 7 commits intomasterfrom
avdunn/update-samples
Jun 30, 2020
Merged

Sample enhancements: Remove token cache file, add properties file#7
Avery-Dunn merged 7 commits intomasterfrom
avdunn/update-samples

Conversation

@Avery-Dunn
Copy link
Copy Markdown
Contributor

@Avery-Dunn Avery-Dunn commented May 26, 2020

Implements changes discussed in #6

  • Removes the sample_cache.json file of dummy data, so that the sample only uses the in-memory token cache
  • Adds an application.properties file, to demonstrate better code practices by not having the user hard-code properties in the main class of the sample

Also implements further changes discussed outside of #6

  • Call the try/catch block with the acquireTokenSilently and acquireTokenUsernamePassword methods twice, so that it demonstrates the silent/not silent pattern fully: first what happens when acquireTokenSilently fails and needs to fall back on a flow-specific acquireToken call, and then what happens when acquireTokenSilently succeeds
  • Add a function to filter the accounts based on user name, like an existing comment in the sample suggested the user does in a 'real' application

@Avery-Dunn Avery-Dunn requested review from SomkaPe and sangonzal May 26, 2020 20:33
@Avery-Dunn Avery-Dunn requested a review from sangonzal June 9, 2020 17:54
Copy link
Copy Markdown
Contributor

@sangonzal sangonzal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The configuration changes look good. I still don't think we should be getting rid of 'readDataFromFile', or hard coding the account. @SomkaPe had some ideas on how to improve this part when he filed the issue, I think it would be useful to schedule some time with him to understand the changes he wanted to make.

@sangonzal
Copy link
Copy Markdown
Contributor

These changes should also be made in the samples included in the main repository. I would recommend waiting until we agree on the changes that are necessary before porting them.

clientId = properties.getProperty("CLIENT_ID");
username = properties.getProperty("USER_NAME");
password = properties.getProperty("USER_PASSWORD");
//Junk account used to pre-fill cache
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not get idea behind it - in samples we definitely do no want to show how to pre-fill cache - especially with
"junk account"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before these changes, the sample had this:

// Take first account in the cache. In a production application, you would filter
// accountsInCache to get the right account for the user authenticating.
IAccount account = accountsInCache.iterator().next();

However, it didn't make much sense to have a comment telling the user should do in a 'real' application when it'd be pretty simple to show it, so I made the getAccountByUsername() helper function to give an example of what they could do. But, with an empty cache that function would only search through a set that was "empty" or "had the one account we're looking for", which wouldn't be a very common scenario in an application with more than one user.

So, rather than having either a unrealistic example of getting an account or having no example at all, I figured adding a junk account to the cache would show a more 'realistic' flow of getting a set of accounts from the cache and searching through something that wasn't empty.

However, I'll definitely add more info the comment above that, explaining that it's only done for the sample and wouldn't be something that happens in a 'real' application.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we need to keep sample as close to real applications as possible, for me "fake account" sounds very far from real applications

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, I just removed accounts and TokenCacheAspect.java entirely, and I guess we can demonstrate that side of things in some new sample focused on persistence.

I also added a few more clarifying comments/printed statements about how all of the account stuff is supposed to be empty on the first run, just so users don't think they're missing something when nothing happens.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you push latest changes ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, looks like there was an auth issue with Git when I thought I pushed them yesterday. Just pushed them now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants