Tutorial:
Method 1: It's very simple and the better method, find a friend (mutual trust is needed as you must share account information), have him set his Xbox One as your Home Xbox. You then set your Xbox One as his Home Xbox. This can be done in the settings, and then scrolling to the bottom where it says 'Set as My Home Xbox.' You are now sharing games. I don't recommend trying to do this with people online.
Method 2: It is also possible for one person to have multiple people sharing with him. If one person were to make his Xbox One the Home Xbox for two other people, he can then play his purchases, along with the purchases of the two other people. He can then do this for 3, 4, 5 or more people. This method only works if you know people willing to share their library with you even when you're not sharing yours. Keep in mind this is only beneficial for a single individual; the person who's Xbox One is set as the Home Xbox for all their friends.
Explanation:
The way that game sharing works is that it takes advantage of the Dual License that comes with each purchase of a Digital Game. If I buy a game, I get an Xbox License for my Home Xbox and a User License for my Gamertag.
When I set my Home Xbox to a friends Xbox One, he then gets the Xbox License for as long as that is my Home Xbox. He can then play all the games I purchase because the Xbox License allows all people to play games on my Home Xbox (his Xbox One). I then can play games using the User License on an away system, one that isn't my Home Xbox (my Xbox One). You are taking advantage of the Dual License. So if he makes your Xbox One his Home Xbox, you effectively use all 4 licenses and it allows you to share games.
WARNING:
You can only set your Home Xbox 3 times per year so be careful. You can possibly end up with someone else's Xbox One as your Home Xbox for a whole year. This means that anything you buy can only be played by you on your Xbox One since he has the Xbox License. Anyone else on your Xbox One can't play your games unless you are signed in.
Game sharing works best when only you use your Xbox One and your friend only uses his otherwise there will be some games other accounts on your Xbox One can't play. You can play everything on your Xbox One (yours and his purchases) but other accounts can only play your friends purchases (because you have his Xbox License). They can't play anything you buy (because he has your Xbox License and you have only the User License). This applies for accounts on your friends Xbox One.
If you simply want to play a game at a friends house, just sign in with your account and download the game. You'll use your User License and be able to play. When you leave, the game will stop working. Just like if you take the disc to his house and then bring it back home. The method I outlined is for a more permanent library sharing method.
License Transfer:
When you are done sharing games, fret not, because when you switch your Home Xbox back to your Xbox One, all your Xbox Licenses will transfer, they are tied to your Home Xbox. This allows you to purchase games while still game sharing and then keep the games you purchased when you are done. Keep in mind, as stated earlier, you can only switch your Xbox Home 3 times per year.
Q&A:
Q: Can both people play the same game at the same time?
A: Yes, both parties can play the same game at the same time. This works because Microsoft allows the Xbox License to let anyone play the game on the Home Xbox while you are playing the game with the User License on an away Xbox One. That way other accounts aren't limited to only playing when you aren't.
Q: Does it have to be bought from the Xbox One store or will this work with Disc Games?
A: It has to be a Digital Game because it uses the Dual License for the game. Disc Games you install but then still need the disc to play it. That means to share disc games, it works like the old days, you take the disc to a friends house.
Q: Will the downloaded content remain on my Xbox One, even when I delete their profile?
A: So long as their Home Xbox is set to your Xbox One, their profile shouldn't have to be there, it is needed to download their stuff however. To be on the safe side, leave it on your Xbox One. The only way you should lose their content, is if they change their Home Xbox back to their Xbox One.
Q: Can you use this same method to share games on the Playstation 4?
A: Yes you can, you sign in as your buddy and then go to settings. You then activate your Playstation 4 as his primary PS4. He will then do the same on his console. There may be a limit on the number of times you can change your primary console so be careful.
The reason there are Dual Licenses is because Microsoft wanted you to be able to play your Digital Games at a friends house. You are now successfully exploiting Microsoft's generosity . Let me know if anything isn't spelled correctly or explained well enough.