Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
How to use OAuth2 ResourceServer with WebApi?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 30 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Brad Laney  
View profile  
 More options Jul 26 2012, 6:47 pm
From: Brad Laney <brad.j.la...@gmail.com>
Date: Thu, 26 Jul 2012 15:47:57 -0700 (PDT)
Local: Thurs, Jul 26 2012 6:47 pm
Subject: How to use OAuth2 ResourceServer with WebApi?

This is the part I'm battling with:

resourceServer.GetPrincipal(HttpRequestMessageBase, Uri, string[]);

WebApi exposes HttpRequestMessage, not HttpRequestMessageBase.

public class OAuthTokenAuthenticationOperationHandler :
OrderedFilterAttribute
{
public override void
OnActionExecuting(System.Web.Http.Controllers.HttpActionContext
actionContext)
{
actionContext.Request // problem


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Arnott  
View profile  
 More options Jul 26 2012, 9:34 pm
From: Andrew Arnott <andrewarn...@gmail.com>
Date: Thu, 26 Jul 2012 18:34:47 -0700
Local: Thurs, Jul 26 2012 9:34 pm
Subject: Re: [dotnetopenauth] How to use OAuth2 ResourceServer with WebApi?

I'm having a hard time understanding the problem.  Is there some API you'd
like to pass your HttpRequestMessage to but the API only takes
HttpRequestMessageBase ?  If so, which API is it?

--
--
Andrew Arnott
"I [may] not agree with what you have to say, but I'll defend to the death
your right to say it." - S. G. Tallentyre

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ryan Rousseau  
View profile  
 More options Jul 26 2012, 10:58 pm
From: Ryan Rousseau <ryan.rouss...@gmail.com>
Date: Thu, 26 Jul 2012 21:58:24 -0500
Local: Thurs, Jul 26 2012 10:58 pm
Subject: Re: [dotnetopenauth] How to use OAuth2 ResourceServer with WebApi?

Brad - I've got some code I can share with you tomorrow. I can't remember
exactly what I did but I think I created a HttpRequestMessageBase and set
the values from the HttpRequestMessage.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brad Laney  
View profile  
 More options Jul 27 2012, 1:40 am
From: Brad Laney <brad.j.la...@gmail.com>
Date: Fri, 27 Jul 2012 00:40:50 -0500
Local: Fri, Jul 27 2012 1:40 am
Subject: Re: [dotnetopenauth] How to use OAuth2 ResourceServer with WebApi?

The problem is that the ResourceServer class, which is used for validating
the request, takes in an HttpRequestMessageBase.

WebApi, through filters (which is where you would put authentication for
requests) exposes only an HttpRequest object, not an HttpRequestMessage or
an HttpRequestMessageBase

I'm talking about code, from the resource server example in oauth2, the
class is the AuthenticationManager class or something like that. It's the
only class with the word manager in it :P

I'll keep an eye out for your post tomorrow ryan, but that sort of sounds
dangerous >_<. I hate relying on manually constructing request classes like
that.

Andrew: The main problem is that the method for validating the request does
not take in an HttpRequest. It only accepts HttpRequestMessageBase and
HttpRequestMessageProperty

On Thu, Jul 26, 2012 at 9:58 PM, Ryan Rousseau <ryan.rouss...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ryan Rousseau  
View profile  
 More options Jul 27 2012, 8:07 am
From: Ryan Rousseau <ryan.rouss...@gmail.com>
Date: Fri, 27 Jul 2012 07:07:52 -0500
Local: Fri, Jul 27 2012 8:07 am
Subject: Re: [dotnetopenauth] How to use OAuth2 ResourceServer with WebApi?

It's actually in the gist for my webapi filter -
https://gist.github.com/2972742

The part you'd be interested in is:

// TODO FIXME dnoa doesn't support HttpRequestMessage - manually
creating HttpRequestMessageProperty until they do
var request = new HttpRequestMessageProperty();
request.Headers[HttpRequestHeader.Authorization] =
actionContext.Request.Headers.Authorization.ToString();
var requestUri = actionContext.Request.RequestUri;

It's not ideal, but I don't think it's too bad until support for
HttpRequestMessage is added.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aleksander Heintz  
View profile  
 More options Jul 27 2012, 9:03 am
From: Aleksander Heintz <alxa...@alxandr.me>
Date: Fri, 27 Jul 2012 06:03:40 -0700 (PDT)
Local: Fri, Jul 27 2012 9:03 am
Subject: Re: [dotnetopenauth] How to use OAuth2 ResourceServer with WebApi?

I'm doing something of the same (by the way, I have OAuth2 resource server
working seamingly perfectly with web api, I'll share the code when it's a
bit less coupled to the tests I'm currently running). I used the sources
found https://github.com/DavidChristiansen/DotNetOpenAuth.WebAPI.40 here.
He uses an even dirtier trick though. He just wraps
HttpContext.Current.Request in a HttpRequestBaseWrapper (or whatever it's
called), but it works, and for now get's the job done.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brad Laney  
View profile  
 More options Jul 27 2012, 11:30 am
From: Brad Laney <brad.j.la...@gmail.com>
Date: Fri, 27 Jul 2012 08:30:59 -0700 (PDT)
Local: Fri, Jul 27 2012 11:30 am
Subject: Re: [dotnetopenauth] How to use OAuth2 ResourceServer with WebApi?

That is VERY confusing. Because the example does not use the authorization
header, it uses NAME.

var operationMessage =
OperationContext.Current.RequestContext.RequestMessage.Properties[HttpReque stMessageProperty.Name]
as HttpRequestMessageProperty;

Is that because WCF changes it to name? I guess I'll try the code and hope
that it works in all situations.

It would be real nice to hear that support for more objects in the
immediate future!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aleksander Heintz  
View profile  
 More options Jul 27 2012, 12:18 pm
From: Aleksander Heintz <alxa...@alxandr.me>
Date: Fri, 27 Jul 2012 09:18:25 -0700 (PDT)
Local: Fri, Jul 27 2012 12:18 pm
Subject: Re: [dotnetopenauth] How to use OAuth2 ResourceServer with WebApi?

Wait, where did you take that from?
Anyways; this is basically what you
need: https://github.com/DavidChristiansen/DotNetOpenAuth.WebAPI.40/blob/ma...
(plus referenced classes, there are 2 or thee more you need to get it
working).


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brad Laney  
View profile  
 More options Jul 27 2012, 3:52 pm
From: Brad Laney <brad.j.la...@gmail.com>
Date: Fri, 27 Jul 2012 14:52:24 -0500
Local: Fri, Jul 27 2012 3:52 pm
Subject: Re: [dotnetopenauth] How to use OAuth2 ResourceServer with WebApi?

I took that from their oauth2 WCF resource server sample...

On Fri, Jul 27, 2012 at 11:18 AM, Aleksander Heintz <alxa...@alxandr.me>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brad Laney  
View profile  
 More options Jul 27 2012, 3:59 pm
From: Brad Laney <brad.j.la...@gmail.com>
Date: Fri, 27 Jul 2012 14:59:57 -0500
Local: Fri, Jul 27 2012 3:59 pm
Subject: Re: [dotnetopenauth] How to use OAuth2 ResourceServer with WebApi?

It's because it's using SOAP, not a big deal.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brad Laney  
View profile  
 More options Jul 27 2012, 4:10 pm
From: Brad Laney <brad.j.la...@gmail.com>
Date: Fri, 27 Jul 2012 13:10:28 -0700 (PDT)
Local: Fri, Jul 27 2012 4:10 pm
Subject: Re: How to use OAuth2 ResourceServer with WebApi?

Okay so I put that into use. But I had to change it from a delegating
handler because I need to access the scopes from the AuthorizeAttribute on
the actions. My scopes are access types. "public", "admin", etc.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aleksander Heintz  
View profile  
 More options Jul 28 2012, 5:49 am
From: Aleksander Heintz <alxa...@alxandr.me>
Date: Sat, 28 Jul 2012 02:49:49 -0700 (PDT)
Local: Sat, Jul 28 2012 5:49 am
Subject: Re: How to use OAuth2 ResourceServer with WebApi?

That works as is with the code. I use a DelegatingHandler and I still use
[Authorize(Roles="users")] no problem (the scopes are treated as roles).


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Arnott  
View profile  
 More options Jul 28 2012, 9:41 am
From: Andrew Arnott <andrewarn...@gmail.com>
Date: Sat, 28 Jul 2012 06:41:24 -0700
Local: Sat, Jul 28 2012 9:41 am
Subject: Re: [dotnetopenauth] Re: How to use OAuth2 ResourceServer with WebApi?

I'm not sure where the idea that DNOA doesn't support this is coming from.
 It sounds like the only limitations I'm really hearing are in the samples
themselves, which shouldn't be construed as lack of support for other
scenarios in the library itself.

Brad said:

>  The problem is that the ResourceServer class, which is used for
> validating the request, takes in an HttpRequestMessageBase.

Actually, ResourceServer has two overloads: one takes HttpRequestBase and
the other takes HttpRequestMessageProperty.  Everything is representable as
an HttpRequestBase, so this should cover every scenario.

> WebApi, through filters (which is where you would put authentication for
> requests) exposes only an HttpRequest object, not an HttpRequestMessage or
> an HttpRequestMessageBase

There are several APIs in ASP.NET that deal in HttpRequest types, and this
is *very* easy to turn into an HttpRequestBase instance: just wrap it with
a HttpRequestWrapper, as the constructor for HttpRequestWrapper takes an
HttpRequest.  That's the class's express purpose.

> I'm talking about code, from the resource server example in oauth2, the
> class is the AuthenticationManager class or something like that. It's the
> only class with the word manager in it :P

It sounds like you're referring to the sample's OAuthAuthorizationManager
class.  And yes, that's written for WCF -- not WebAPI.  I'm not yet
familiar with WebAPI so another approach sounds appropriate and could be
considered fully supported.  See further below.

Andrew: The main problem is that the method for validating the request does

> not take in an HttpRequest. It only accepts HttpRequestMessageBase and
> HttpRequestMessageProperty

I suspect you meant *HttpRequestBase *and HttpRequestMessageProperty.  And
as I said above, HttpRequest is trivially convertable to HttpRequestBase.

Alek said:

> I'm doing something of the same (by the way, I have OAuth2 resource server
> working seamingly perfectly with web api, I'll share the code when it's a
> bit less coupled to the tests I'm currently running). I used the sources
> found https://github.com/DavidChristiansen/DotNetOpenAuth.WebAPI.40 here.
> He uses an even dirtier trick though. He just wraps
> HttpContext.Current.Request in a HttpRequestBaseWrapper (or whatever it's
> called), but it works, and for now get's the job done.

I haven't studied David's sample yet, but as I state above,
HttpRequestWrapper is *not* a dirty trick.  It's the official
Microsoft-supplied way of converting HttpRequest into an HttpRequestBase.

I hope this helps.

--
Andrew Arnott
"I [may] not agree with what you have to say, but I'll defend to the death
your right to say it." - S. G. Tallentyre

On Sat, Jul 28, 2012 at 2:49 AM, Aleksander Heintz <alxa...@alxandr.me>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aleksander Heintz  
View profile  
 More options Jul 28 2012, 11:02 am
From: Aleksander Heintz <alxa...@alxandr.me>
Date: Sat, 28 Jul 2012 08:02:33 -0700 (PDT)
Local: Sat, Jul 28 2012 11:02 am
Subject: Re: [dotnetopenauth] Re: How to use OAuth2 ResourceServer with WebApi?

I think you've misunderstood something (or I have). The problem is that
there is introduced a new Request-class in Web API named
System.Net.Http.HttpRequestMessage<http://msdn.microsoft.com/en-us/library/system.net.http.httprequestme...>.
It has (next to) nothing in common with the regular HttpRequest. For
instance, as far as I can tell, HttpRequestMessage does *not* parse
form-data, and almost all of the methods exposed on the object is async
only.

Oh, and as a side-node; I do *not* think HttpRequestWrapper is a dirty
trick; I think using the ThreadStatic property HttpContext.Current is.
Also, using ThreadStatic properties in an async method makes my hair
tingle, and not in a good way...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Arnott  
View profile  
 More options Jul 28 2012, 12:18 pm
From: Andrew Arnott <andrewarn...@gmail.com>
Date: Sat, 28 Jul 2012 09:18:25 -0700
Local: Sat, Jul 28 2012 12:18 pm
Subject: Re: [dotnetopenauth] Re: How to use OAuth2 ResourceServer with WebApi?

Alek,

In reviewing the docs for HttpRequestMessage, I don't see any way to access
the POST entity at all, parsed or not.  Am I missing something?

--
Andrew Arnott
"I [may] not agree with what you have to say, but I'll defend to the death
your right to say it." - S. G. Tallentyre

On Sat, Jul 28, 2012 at 8:02 AM, Aleksander Heintz <alxa...@alxandr.me>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aleksander Heintz  
View profile  
 More options Jul 28 2012, 12:24 pm
From: Aleksander Heintz <alxa...@alxandr.me>
Date: Sat, 28 Jul 2012 09:24:14 -0700 (PDT)
Local: Sat, Jul 28 2012 12:24 pm
Subject: Re: [dotnetopenauth] Re: How to use OAuth2 ResourceServer with WebApi?

It's called Body I think. Oh, and if you'd like a more indepth discussion
(on a more efficient medium) I'm avail at rizzoma.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aleksander Heintz  
View profile  
 More options Jul 28 2012, 12:54 pm
From: Aleksander Heintz <alxa...@alxandr.me>
Date: Sat, 28 Jul 2012 09:54:17 -0700 (PDT)
Local: Sat, Jul 28 2012 12:54 pm
Subject: Re: [dotnetopenauth] Re: How to use OAuth2 ResourceServer with WebApi?

I found this: request.Content.ReadAsFormDataAsync()


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aleksander Heintz  
View profile  
 More options Jul 28 2012, 2:24 pm
From: Aleksander Heintz <alxa...@alxandr.me>
Date: Sat, 28 Jul 2012 11:24:14 -0700 (PDT)
Local: Sat, Jul 28 2012 2:24 pm
Subject: Re: [dotnetopenauth] Re: How to use OAuth2 ResourceServer with WebApi?

So, eh, yeah... Have fun:  https://gist.github.com/3194281


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brad Laney  
View profile  
 More options Jul 30 2012, 1:16 pm
From: Brad Laney <brad.j.la...@gmail.com>
Date: Mon, 30 Jul 2012 10:16:57 -0700 (PDT)
Local: Mon, Jul 30 2012 1:16 pm
Subject: Re: [dotnetopenauth] Re: How to use OAuth2 ResourceServer with WebApi?

Thanks Aleksander, I'll use that class. Still a bit scary though.
But yeah, that's what I was failing to mention is the HttpRequestMessage
class and all the classes in WebApi are completely unrelated to the normal
Web or MVC classes.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brad Laney  
View profile  
 More options Jul 30 2012, 1:19 pm
From: Brad Laney <brad.j.la...@gmail.com>
Date: Mon, 30 Jul 2012 10:19:34 -0700 (PDT)
Local: Mon, Jul 30 2012 1:19 pm
Subject: Re: [dotnetopenauth] Re: How to use OAuth2 ResourceServer with WebApi?

Unfortunately I won't be able to use async quite yet. Do you know if that
will cause a significant problem?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brad Laney  
View profile  
 More options Jul 30 2012, 1:22 pm
From: Brad Laney <brad.j.la...@gmail.com>
Date: Mon, 30 Jul 2012 10:22:45 -0700 (PDT)
Local: Mon, Jul 30 2012 1:22 pm
Subject: Re: [dotnetopenauth] Re: How to use OAuth2 ResourceServer with WebApi?

Actually.. what version of webapi release are you using? I am using RC1 and
most of the properties you have here don't work. Are they extension methods
that you have that I am missing?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aleksander Heintz  
View profile  
 More options Jul 30 2012, 2:17 pm
From: Aleksander Heintz <alxa...@alxandr.me>
Date: Mon, 30 Jul 2012 11:17:23 -0700 (PDT)
Local: Mon, Jul 30 2012 2:17 pm
Subject: Re: [dotnetopenauth] Re: How to use OAuth2 ResourceServer with WebApi?

Yeah, most of them are extension-methods, but I included the
using-statements, so that shouldn't be a problem. Also, it should be fairly
easy to rewrite this to not use the async/await-keywords. Just replace any
await keywords with continuation-statements like shown below:

// with await
var something = await this.someMethod();
var somethingElse = await something.someOtherMethod();
return somethingElse.value;

// without await
return this.someMethod()
    .ContinueWith(t => t.Result.someOtherMethod()).Unwrap() // takes a
Task<Task<TResult>> and returns a Task<TResult>
    .ContinueWith(t => t.Result.value);

If it hasn't been done, I'll probably do it myself when I have time, though
right now I'm reading for exams that are due in a couple of weeks... Leaves
little time for play-stuff like programming for fun, need to focus on the
math <.<

Oh, and btw; I hate math Q.Q


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brad Laney  
View profile  
 More options Jul 31 2012, 12:40 pm
From: Brad Laney <brad.j.la...@gmail.com>
Date: Tue, 31 Jul 2012 11:40:25 -0500
Local: Tues, Jul 31 2012 12:40 pm
Subject: Re: [dotnetopenauth] Re: How to use OAuth2 ResourceServer with WebApi?

I actually don't have any of those extension methods in my build of RC1

It might be because I'm using the 2010 version of webapi/mvc4? Tough luck
on my part! I went the creation of the property route instead.

On Mon, Jul 30, 2012 at 1:17 PM, Aleksander Heintz <alxa...@alxandr.me>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aleksander Heintz  
View profile  
 More options Jul 31 2012, 2:07 pm
From: Aleksander Heintz <alxa...@alxandr.me>
Date: Tue, 31 Jul 2012 11:07:35 -0700 (PDT)
Local: Tues, Jul 31 2012 2:07 pm
Subject: Re: [dotnetopenauth] Re: How to use OAuth2 ResourceServer with WebApi?

You made sure you hade all the namespaces?
Anyways; I'm using a nightly, but I found those extension-methods on SO,
from someone using RC, so I was sure they should be there...
But I'm also using C# 4.5, and that might be the "problem".


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Arnott  
View profile  
 More options Jul 31 2012, 2:40 pm
From: Andrew Arnott <andrewarn...@gmail.com>
Date: Tue, 31 Jul 2012 11:40:03 -0700
Local: Tues, Jul 31 2012 2:40 pm
Subject: Re: [dotnetopenauth] How to use OAuth2 ResourceServer with WebApi?

FWIW, you can using async stuff even if you're targeting .NET 4.0, as
presented in Stephen Toub's blog post.
http://blogs.msdn.com/b/pfxteam/archive/2012/04/26/10297848.aspx

--
--
Andrew Arnott
"I [may] not agree with what you have to say, but I'll defend to the death
your right to say it." - S. G. Tallentyre

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 1 - 25 of 30   Newer >
« Back to Discussions « Newer topic     Older topic »