I have following SharePoint components--
- A SharePoint online site with bunch of document libraries.
- Deployed workflow custom actions using visual studio and sandbox solution.
- Created provider hosted app with app web hosted on Azure web server.
- Deployed one WCF service along with app web hosted on Azure web server. Web service is anonymous and can be called from anywhere.
- I am calling WCF web service using SendHTTP activity from Visual studio custom action.
- WCF tries to use S2SSecurityToken sent by SendHTTP activity and access host web by creating client context using tokenhelp class.
My problem starts now,
I cannot create access token using S2S security token. It gives me following exception --
System.IdentityModel.Tokens.SecurityTokenValidationException: The token being parsed does not have an issuer. at Microsoft.IdentityModel.S2S.Tokens.JsonWebSecurityTokenHandler.ReadTokenCore(String token, Boolean isActorToken) at Microsoft.IdentityModel.S2S.Tokens.JsonWebSecurityTokenHandler.ReadToken(String token)
I have tried to create client context using username/password and SharePointOnlineCredentials class and it was successful.
But question is --
Is it possible to access host web list item from custom azure hosted wcf service using some sort of header token? I want to use current user's credential to access host web.
Sample code I have used within web service is --
WebHeaderCollection headers = WebOperationContext.Current.IncomingRequest.Headers; string contextTokenSting = headers["S2SSecurityContext"]; SharePointContextToken contextToken = TokenHelper.ReadAndValidateContextToken(contextTokenSting, sharepointUrl.Authority); string accessToken = TokenHelper.GetAccessToken(contextToken, sharepointUrl.Authority).AccessToken; ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(sharepointUrl.ToString(), accessToken); Web web = clientContext.Web; File file = web.GetFileByServerRelativeUrl(serverrelative); clientContext.Load(file); clientContext.ExecuteQuery();