OfficeDevPnP.Core AuthenticationManager GetAppOnlyAuthenticatedContext is throwing error

%3CLINGO-SUB%20id%3D%22lingo-sub-30479%22%20slang%3D%22en-US%22%3EOfficeDevPnP.Core%20AuthenticationManager%20GetAppOnlyAuthenticatedContext%20is%20throwing%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-30479%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20thinking%20of%20trying%20OfficeDevPnp%20Core%20dll%20for%20CSOM%20operations%20in%20my%20current%20project.%20I'm%20doing%20a%20POC%20to%20check%20if%20add-in%20only%20context%20works%20for%20SharePoint%202013%20on-premises.%20I%20have%20checked%20%22GetNetworkCredentialAuthenticatedContext%22%20method%20and%20it%20worked.%20But%20the%20method%20that%20gets%20add-in%20only%20context%20is%20not%20working%20and%20it%20throws%20error%20that%20object%20reference%20set%20to%20null.%20I%20want%20to%20understand%20if%20this%20method%20works%20for%20On-Premises.%20Got%20this%20doubt%20because%20it%20expects%20appsecret%20as%20a%20parameter%20and%20as%20I%20know%20appsecret%20(Client%20Secret)%20is%20not%20necessary%20for%20High%20Trust%20add-ins.%20I%20have%20registered%20an%20add-in%20from%20appregnew.aspx.%20And%20provided%20it%20Add-in%20only%20permissions.%20But%20my%20console%20job%20where%20I%20get%20the%20add-in%20only%20context%20fails.%20can%20someone%20let%20me%20know%20what%20could%20be%20wrong%20here%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-30556%22%20slang%3D%22en-US%22%3ERe%3A%20OfficeDevPnP.Core%20AuthenticationManager%20GetAppOnlyAuthenticatedContext%20is%20throwing%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-30556%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAdd-in%20authentication%20works%20for%20SharePoint%202013%20in%20both%20%22add-in%20only%22%20and%20%22add-in%2Buser%22%20types.%20If%20you%20want%20to%20setup%20High%20Trust%20add-in%20you%20don't%20need%20client%20secret%20(it%20is%20used%20for%20Low%20Trust%20scenario).%20To%20setup%20high%20trust%20add-in%20you%20need%20to%20create%20X.509%20certificate%2C%20add%20it%20as%20trusted%20root%20authority%20and%20trusted%20security%20token%20issuer%20to%20SharePoint%20farm.%20Also%20if%20you%20need%20add-in%20only%20context%2C%20make%20sure%20that%20issuer%20id%20and%20client%20id%20for%20your%20add-in%20are%20the%20same.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMore%20details%20here%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Foffice%2Ffp179901.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Foffice%2Ffp179901.aspx%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-30516%22%20slang%3D%22en-US%22%3ERe%3A%20OfficeDevPnP.Core%20AuthenticationManager%20GetAppOnlyAuthenticatedContext%20is%20throwing%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-30516%22%20slang%3D%22en-US%22%3E%3CP%3ECan%20you%20post%20the%20stack%20trace%20for%20the%20error%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

I am thinking of trying OfficeDevPnp Core dll for CSOM operations in my current project. I'm doing a POC to check if add-in only context works for SharePoint 2013 on-premises. I have checked "GetNetworkCredentialAuthenticatedContext" method and it worked. But the method that gets add-in only context is not working and it throws error that object reference set to null. I want to understand if this method works for On-Premises. Got this doubt because it expects appsecret as a parameter and as I know appsecret (Client Secret) is not necessary for High Trust add-ins. I have registered an add-in from appregnew.aspx. And provided it Add-in only permissions. But my console job where I get the add-in only context fails. can someone let me know what could be wrong here?

2 Replies
Highlighted

Can you post the stack trace for the error?

Highlighted

Hi,

 

Add-in authentication works for SharePoint 2013 in both "add-in only" and "add-in+user" types. If you want to setup High Trust add-in you don't need client secret (it is used for Low Trust scenario). To setup high trust add-in you need to create X.509 certificate, add it as trusted root authority and trusted security token issuer to SharePoint farm. Also if you need add-in only context, make sure that issuer id and client id for your add-in are the same.

 

More details here: https://msdn.microsoft.com/en-us/library/office/fp179901.aspx