If the AuthenticationProviderName is the same, I want to share the AuthenticationProvider
See original GitHub issueCategory
- 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:
- Created 3 years ago
- Comments:9 (4 by maintainers)
Top GitHub Comments
There are a couple of workarounds for in case folks want to ensure the same IAuthenticationManager instance is used:
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.
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!