Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OK, after a <em>lot</em> of stepping through the various libraries with a debugger, I think you do it like this: <a href="https://github.com/dylanbeattie/OAuthStack">https://github.com/dylanbeattie/OAuthStack</a></p> <p>There's two key integration points. First, a custom filter attribute that's used on the server to decorate the resource endpoints that should be secured with OAuth2 authorization:</p> <pre><code> /// &lt;summary&gt;Restrict this service to clients with a valid OAuth2 access /// token granting access to the specified scopes.&lt;/summary&gt; [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true)] public class RequireOAuth2ScopeAttribute : RequestFilterAttribute { private readonly string[] oauth2Scopes; public RequireOAuth2ScopeAttribute(params string[] oauth2Scopes) { this.oauth2Scopes = oauth2Scopes; } public override void Execute(IHttpRequest request, IHttpResponse response, object requestDto) { try { var authServerKeys = AppHostBase.Instance.Container.ResolveNamed&lt;ICryptoKeyPair&gt;("authServer"); var dataServerKeys = AppHostBase.Instance.Container.ResolveNamed&lt;ICryptoKeyPair&gt;("dataServer"); var tokenAnalyzer = new StandardAccessTokenAnalyzer(authServerKeys.PublicSigningKey, dataServerKeys.PrivateEncryptionKey); var oauth2ResourceServer = new DotNetOpenAuth.OAuth2.ResourceServer(tokenAnalyzer); var wrappedRequest = new HttpRequestWrapper((HttpRequest)request.OriginalRequest); HttpContext.Current.User = oauth2ResourceServer.GetPrincipal(wrappedRequest, oauth2Scopes); } catch (ProtocolFaultResponseException x) { // see the GitHub project for detailed error-handling code throw; } } } </code></pre> <p>Second, this is how you hook into the ServiceStack HTTP client pipeline and use DotNetOpenAuth to add the OAuth2 <code>Authorization: Bearer {key}</code> token to the outgoing request:</p> <pre><code>// Create the ServiceStack API client and the request DTO var apiClient = new JsonServiceClient("http://api.mysite.com/"); var apiRequestDto = new Shortlists { Name = "dylan" }; // Wire up the ServiceStack client filter so that DotNetOpenAuth can // add the authorization header before the request is sent // to the API server apiClient.LocalHttpWebRequestFilter = request =&gt; { // This is the magic line that makes all the client-side magic work :) ClientBase.AuthorizeRequest(request, accessTokenTextBox.Text); } // Send the API request and dump the response to our output TextBox var helloResponseDto = apiClient.Get(apiRequestDto); Console.WriteLine(helloResponseDto.Result); </code></pre> <p>Authorized requests will succeed; requests with a missing token, expired token or insufficient scope will raise a <code>WebServiceException</code></p> <p>This is still very much proof-of-concept stuff, but seems to work pretty well. I'd welcome feedback from anyone who knows ServiceStack or DotNetOpenAuth better than I do.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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