Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF - Custom Credentials & Security Tokens
    primarykey
    data
    text
    <p>I'm fairly new to WCF development and have run into a couple problems whilst learning the framework. I have a service api which must support both REST &amp; SOAP. So far this has been easy to implement especially with WCF4 and routing.</p> <p>I am currently working on authorization and have managed to extend AuthorizationManager by creating two new manager classes: "ApiKeyAuthorizationManager" &amp; "ApiKeyAndTokenAuthorizationManager"</p> <p>Most of my services will require an ApiKey and Token (GUIDS) to be present; when initially authenticating, you simply need a valid ApiKey and password to receive a Token.</p> <p>So far REST is working perfectly as the Authorization managers look to the query string to get ApiKey and/or Token.</p> <p>So for example a service uri would look like: *<a href="http://api.domain.com/Service/Operation/" rel="nofollow noreferrer">http://api.domain.com/Service/Operation/</a>{someVariableValue}?ApiKey=GUID&amp;Token=GUID</p> <p>My problem now comes with authorizing SOAP service calls. I've done a little bit of research and have come to a few conclusions I wanted to verify are correct before implementing.</p> <p>In order to authorize SOAP with custom credentials I should:</p> <ol> <li>Create custom service token (<a href="http://msdn.microsoft.com/en-us/library/ms731872.aspx" rel="nofollow noreferrer">MSDN</a>)</li> <li>Extend WCF by creating a custom SecurityTokenProvider, SecurityTokenAuthenticator, and SecurityTokenSerializer (<a href="http://msdn.microsoft.com/en-us/library/ms730868.aspx" rel="nofollow noreferrer">MSDN</a>)</li> <li>Extend WCF by creating custom AuthorizationPolicies (<a href="http://msdn.microsoft.com/en-us/library/ms751416.aspx" rel="nofollow noreferrer">MSDN</a>)</li> </ol> <p><em>Am I on the right track for this? Are all these steps needed to fit my scenario? Seems like so much customization for just verifying a credential made up of two GUIDs.</em></p> <p>Thanks!</p> <hr> <p><strong>[EDIT #1]</strong></p> <p>This has been a very difficult task. Custom credentials and security tokens is nearly undocumented. Finding quality blog posts itself has proven near impossible. I've kept plugging away and am so close to have a working solution. I've even hit the same road blocks as described in <a href="https://stackoverflow.com/questions/563037/wcf-authentication-with-custom-clientcredentials-what-is-the-clientcredentialtyp">this post</a>.</p> <p>When I try to access my service to uncover the wsdl or mex I receive this error:</p> <p><code></p> <pre> The service encountered an error. An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is: System.InvalidOperationException: An exception was thrown in a call to a policy export extension. Extension: System.ServiceModel.Channels.SymmetricSecurityBindingElement Error: Specified argument was out of the range of valid values. Parameter name: parameters ----> System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: parameters at System.ServiceModel.Security.WSSecurityPolicy.CreateTokenAssertion(MetadataExporter exporter, SecurityTokenParameters parameters, Boolean isOptional) at System.ServiceModel.Security.WSSecurityPolicy.CreateWsspSignedSupportingTokensAssertion(MetadataExporter exporter, Collection`1 signed, Collection`1 signedEncrypted, Collection`1 optionalSigned, Collection`1 optionalSignedEncrypted) at System.ServiceModel.Security.WSSecurityPolicy.CreateWsspSupportingTokensAssertion(MetadataExporter exporter, Collection`1 signed, Collection`1 signedEncrypted, Collection`1 endorsing, Collection`1 signedEndorsing, Collection`1 optionalSigned, Collection`1 optionalSignedEncrypted, Collection`1 optionalEndorsing, Collection`1 optionalSignedEndorsing, AddressingVersion addressingVersion) at System.ServiceModel.Security.WSSecurityPolicy.CreateWsspSupportingTokensAssertion(MetadataExporter exporter, Collection`1 signed, Collection`1 signedEncrypted, Collection`1 endorsing, Collection`1 signedEndorsing, Collection`1 optionalSigned, Collection`1 optionalSignedEncrypted, Collection`1 optionalEndorsing, Collection`1 optionalSignedEndorsing) at System.ServiceModel.Channels.SecurityBindingElement.ExportSymmetricSecurityBindingElement(SymmetricSecurityBindingElement binding, MetadataExporter exporter, PolicyConversionContext policyContext) at System.ServiceModel.Channels.SecurityBindingElement.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context) at System.ServiceModel.Description.MetadataExporter.ExportPolicy(ServiceEndpoint endpoint) --- End of inner ExceptionDetail stack trace --- at System.ServiceModel.Description.ServiceMetadataBehavior.MetadataExtensionInitializer.GenerateMetadata() at System.ServiceModel.Description.ServiceMetadataExtension.EnsureInitialized() at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.InitializationData.InitializeFrom(ServiceMetadataExtension extension) at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.GetInitData() at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.TryHandleDocumentationRequest(Message httpGetRequest, String[] queries, Message& replyMessage) at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.ProcessHttpRequest(Message httpGetRequest) at SyncInvokeGet(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet) </pre> <p></code></p> <p>If you have any idea what might be causing this I'd love some help.</p> <hr> <p><strong>[EDIT #2]</strong></p> <p>It seems Microsoft doesn't want to update their samples to show how to allow wsdl support for custom credentials / tokens. <a href="http://social.msdn.microsoft.com/forums/en-US/wcf/thread/1e3a71bc-7cef-414e-80dc-711cdea370e0" rel="nofollow noreferrer">See here</a>. Anyone have an idea how to get this working? What's the point of making a framework extensible if there's no documentation how to extend it?!?</p> <hr> <p><strong>[EDIT #3]</strong></p> <p>As stated in my comment below... I have TransportWithMessageCredential working just fine using UserNameSecurityToken. Unfortunately, my services will end up requiring custom tokens when it's time to implement some more advanced features that I have planned.</p> <p><em>What I'm looking for as an answer would be:</em></p> <p><strong>How to support custom service credentials and tokens <em>with</em> WSDL support?</strong> </p> <p>Currently, following Microsoft's examples, you can only use custom credentials by using ChannelFactory and creating a custom binding on the client. I would rather not deal with that.</p> <p>If this question remains unanswered, I'll keep upping the bounty. As soon as I can get this all working I'll write up a blog tutorial on all the steps required to creating a custom security solution.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload