question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

If the AuthenticationProviderName is the same, I want to share the AuthenticationProvider

See original GitHub issue

Category

  • Feature request

Describe the feature

Currently, even if the AuthenticationProviderName of appsettings.json is the same, AuthenticationProvider refers to another instance. In the following case, SiteA and SiteB have the same “InteractiveFlow” but refer to different AuthenticationProvider instances.

appsettings.json

"Credentials": {
    ~
    "InteractiveFlow": {
        "ClientId": "b87659ce-1c11-440b-812b-0b35217d9e83",
        "TenantId": "b8765c9e-30c7-473a-83bc-d907df44a26e",
        "Interactive": {
            "RedirectUri": "http://localhost"
        }
    }
},
"Sites": {
    "Site_A": {
        "SiteUrl": "https://contoso.sharepoint.com/sites/siteA",
        "AuthenticationProviderName": "InteractiveFlow"
    },
    "Site_B": {
        "SiteUrl": "https://contoso.sharepoint.com/sites/siteB",
        "AuthenticationProviderName": "InteractiveFlow"
    }
}

If the AuthenticationProviderName is the same, the initialization parameters in the Credentials are also the same and should be instances in the same state. The problem is that because the instance is different, the information logged in with SiteA is not carried over to SiteB, and you need to login again. Of course, since the ClientId and TenantID are the same, the same authentication will be performed.

Describe the solution you’d like

If the AuthenticationProviderName is the same, I want to share the AuthenticationProvider.

Even if you execute the following code, it will be possible to process with one login. Also, you can login once regardless of the execution order of Event1 and Event2.

async Task Event1()
{
    using (var context = await pnpContextFactory.CreateAsync("Site_A"))
    {
        var web = await context.Web.GetAsync(w => w.Title, w => w.Description, w => w.MasterUrl);
        ~
    }
    using (var context = await pnpContextFactory.CreateAsync("Site_B"))
    {
        var web = await context.Web.GetAsync(w => w.Title, w => w.Description, w => w.MasterUrl);
        ~
    }
}
async Task Event2()
{
    using (var context = await pnpContextFactory.CreateAsync("Site_B"))
    {
        var web = await context.Web.GetAsync(w => w.Title, w => w.Description, w => w.MasterUrl);
        ~
    }
}

Additional context

AuthenticationProviderName is used in Create method from AuthenticationProviderFactory class . How about adding a method like CreateIfAbsent instead of Create and caching it to return the same instance the next time the same name comes in?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jansenbecommented, Oct 11, 2020

There are a couple of workarounds for in case folks want to ensure the same IAuthenticationManager instance is used:

  • Create the IAuthenticationManager yourselve and then pass that into the PnPContextFactory
  • Use the Clone() method on an existing PnPContext

Not sure if we already at this point need to do additional work for this, I’m more in favor for waiting and seeing if there’s more demand.

0reactions
jansenbecommented, Oct 13, 2020

Thanks for your feedback @RYO-4947123 , it resulted in a good discussion about this feature. For now we think the offered workarounds are sufficient, so I’ll be closing this issue. Keep the feedback coming!

Read more comments on GitHub >

github_iconTop Results From Across the Web

spring - Use different AuthenticationProvider depending on ...
In a Spring Security 3.2 based application I need to authenticate users against two different providers, based on a certain pattern in their ......
Read more >
Spring Security Authentication Provider
The Authentication Provider. Spring Security provides a variety of options for performing authentication. These options follow a simple contract ...
Read more >
Multiple Authentication Providers in Spring Security
For a quick demonstration, we'll configure two authentication providers – a custom authentication provider and an in-memory authentication ...
Read more >
Spring Security - Authentication Providers
It is responsible for authenticating a user's credentials and returning an Authentication object that represents the authenticated user. Here is ...
Read more >
Authentication Providers - WebLogic Server
Authentication Providers. Authentication is the mechanism by which callers prove that they are acting on behalf of specific users or systems.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found