CmlLib / CmlLib.Core.Auth.Microsoft

Minecraft Login with Microsoft Xbox account
MIT License
22 stars 4 forks source link

Can you add multiple accounts feature? #10

Closed EvanEvan-17 closed 2 years ago

EvanEvan-17 commented 2 years ago

I'm trying to make my own Launcher for my YouTube Subscribers. I'm looking to support multiple accounts because MANY LAUNCHER SUPPORT MULTIPLE ACCOUNTS. How do I do this? Do I have to make my own code? Or can you add this feature?

EvanEvan-17 commented 2 years ago

Ah man because you don't respond, I have been done making my own code for multiple accounts.

EvanEvan-17 commented 2 years ago

@AlphaBs If you can't add it, then that's fine. I have done making custom launcher and modify many things. Now multiple accounts feature is working in my launcher. But if you can add it, I will appreciate it!

AlphaBs commented 2 years ago

I think it will be great if the library supports multiple accounts. (my launcher also needs this feature!)

so I'm planning to add multiple session manager.

EvanEvan-17 commented 2 years ago

Don't forget to also store the Microsoft User ID returned by MSAL.NET, so you can bind your account data with MSAL.NET if you need it (e.g. to get tokens, etc).

EvanEvan-17 commented 2 years ago

Wow! Are you making a launcher like me? What is the purpose for your launcher? haha

EvanEvan-17 commented 2 years ago

When you add multiple accounts feature? If you can't, give me the tutorial to make custom login handler since I'm updating to the 'rc' version.

AlphaBs commented 2 years ago

Implement your own ICacheManager to return cached session.

AlphaBs commented 2 years ago

working now: a2289dc606efd0376a8ec7bb6080bba464fd9efd

sample: https://github.com/CmlLib/CmlLib.Core.Auth.Microsoft/blob/a2289dc606efd0376a8ec7bb6080bba464fd9efd/src/samples/WinFormTest/MultiAccount.cs

EvanEvan-17 commented 2 years ago

How do I install that version? Is that exist on nuget?

EvanEvan-17 commented 2 years ago

It's actually working since yesterday, with my own code. I've customized many things.

AlphaBs commented 2 years ago

How do I install that version? Is that exist on nuget?

no I have not release yet. you should build it by yourself.

EvanEvan-17 commented 2 years ago

I've tried your sample with dummy device token API (because I'm under 18), but it failed. Without dummy device token API, it success for my first account (since it's on family group) but with dummy device token API, it failed.

AlphaBs commented 2 years ago

what error message? can you show me your code?

AlphaBs commented 2 years ago

please make new issue and explain more detail

EvanEvan-17 commented 2 years ago

Maybe later. I'm no longer testing your sample and I'm now trying to implement this on my own code. Does this multiple accounts feature work with MsalClient? Since the your MsalOAuthApiBase is using accounts.FirstOrDefault()

var result = await MsalApplication.AcquireTokenSilent(Scopes, accounts.FirstOrDefault())
                .ExecuteAsync(cancellationToken);

and also the token invalidation method remove ALL accounts from MSAL storage:

  public static async Task RemoveAccounts(IPublicClientApplication app)
        {
            var accounts = await app.GetAccountsAsync();
            while (accounts.Any())
            {
                var first = accounts.First();
                await app.RemoveAsync(first);
                accounts = await app.GetAccountsAsync();
            }
        }
AlphaBs commented 2 years ago

yes it works. OAuth token does not matter

EvanEvan-17 commented 2 years ago

So if multiple accounts on MSAL.NET, it always read first account? How they know the selected session since they aren't reading a cache? Actually I've customized this, but please answer me so I know how it works.

AlphaBs commented 2 years ago

Actually, I don't know. It's just a code to prove that you can create a multi account like this, not a code that designs and tests the exact behavior.

Again, I can't afford to develop this project now...