I'm currently writing a webpage (front-end and back-end) which exposes a OAuth2 enabled API. I'm already able to generate the tokens, and once I have a token I can get to the "protected" resources (given that I have valid scopes ofc.) However, the problem comes when I access my page in the browser (which is to be the main client for consuming the OAuth2 API). For testing purposes I've made the token short-lived (2 minutes), and the problem is that once those two minutes are up, the client is kicked out of the system, and cannot access his private resources anymore. Now, if there were a 2 minutes delay without any requests using the token, this would be ok, however, since the client has been activily using the service since the token was issued, he should not be booted out.
Just imagine if you went to facebook (or any other page you log into), and after half an hour you were logged out regardles of what you had been doing up till then. If you had done nothing, you might have understood it, but if you were in the middle of answering some comment to a post you just posted, then it would feel rather strange.
So what I need is a way to renew the token, or a way to make the expiration roling, and I have no idea how to do either. Also, there might be better ideas on how to solve this problem that I have not thought about at all, so if you have any other ways of solving this, please do tell.
The OAuth 2 spec supported answer for this is to use refresh tokens to
obtain new access tokens as the access tokens approach their expiration. I
believe DNOA may not yet support refresh tokens for anonymous clients (I
take it your client is running in the browser), but you can certainly try
the auth code grant flow from javascript and see if it works and let us
know what you find. If it's not supported yet, we're interested in adding
it.
On Tuesday, July 24, 2012, Aleksander Heintz wrote:
> I'm currently writing a webpage (front-end and back-end) which exposes a
> OAuth2 enabled API.
> I'm already able to generate the tokens, and once I have a token I can get
> to the "protected" resources (given that I have valid scopes ofc.)
> However, the problem comes when I access my page in the browser (which is
> to be the main client for consuming the OAuth2 API).
> For testing purposes I've made the token short-lived (2 minutes), and the
> problem is that once those two minutes are up, the client is kicked out of
> the system, and cannot access his private resources anymore.
> Now, if there were a 2 minutes delay without any requests using the token,
> this would be ok, however, since the client has been activily using the
> service since the token was issued, he should not be booted out.
> Just imagine if you went to facebook (or any other page you log into), and
> after half an hour you were logged out regardles of what you had been doing
> up till then. If you had done nothing, you might have understood it,
> but if you were in the middle of answering some comment to a post you just
> posted, then it would feel rather strange.
> So what I need is a way to renew the token, or a way to make the
> expiration roling, and I have no idea how to do either. Also, there might
> be better ideas on how to solve this problem that I have not thought about
> at all, so if you have any other ways of solving this, please do tell.
> --
> You received this message because you are subscribed to the Google Groups
> "DotNetOpenAuth" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/dotnetopenid/-/cuTieHJp9JgJ.
> To post to this group, send email to dotnetopenid@googlegroups.com<javascript:_e({}, 'cvml', 'dotnetopenid@googlegroups.com');>
> .
> To unsubscribe from this group, send email to
> dotnetopenid+unsubscribe@googlegroups.com <javascript:_e({}, 'cvml',
> 'dotnetopenid%2Bunsubscribe@googlegroups.com');>.
> For more options, visit this group at
> http://groups.google.com/group/dotnetopenid?hl=en.
-- --
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
However, I keep getting 400 Invalid Request. I'm no expert when it comes to OAuth, so I don't know if the request is wrong or not, but I do know that the code is what I got from the server, and the client_id and client_secrets are correct, as is the redirect_uri. The only code run on the end-point is this:
Turn on logging <http://tinyurl.com/dnoalogs> and see what your auth server
says.
--
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 Tue, Jul 24, 2012 at 8:24 PM, Aleksander Heintz <alxa...@alxandr.me>wrote:
> However, I keep getting 400 Invalid Request. I'm no expert when it comes
> to OAuth, so I don't know if the request is wrong or not, but I do know
> that the code is what I got from the server, and the client_id and
> client_secrets are correct, as is the redirect_uri. The only code run on
> the end-point is this:
> To post to this group, send email to dotnetopenid@googlegroups.com.
> To unsubscribe from this group, send email to
> dotnetopenid+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/dotnetopenid?hl=en.
OK. Well, I'll take a closer look at your request message in the morning
and see if I can figure out what might be going wrong.
--
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 Tue, Jul 24, 2012 at 9:39 PM, Aleksander Heintz <alxa...@alxandr.me>wrote:
> To post to this group, send email to dotnetopenid@googlegroups.com.
> To unsubscribe from this group, send email to
> dotnetopenid+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/dotnetopenid?hl=en.
I figured out the logging :), I just had to change the config (I had just coppied and pasted from the link you just sent me). Anyways; I get this: 2012-07-25 06:57:41,768 (GMT+2) [51] ERROR DotNetOpenAuth.Messaging - Protocol error: redirect_uri_mismatch
And I get it even though I go into my db and copy paste the redirect uri of the client (just to make sure I didn't misspell any). The top of the stack looks like this: at DotNetOpenAuth.Messaging.ErrorUtilities.VerifyProtocol(Boolean condition, String unformattedMessage, Object[] args) at DotNetOpenAuth.OAuth2.ChannelElements.AuthorizationCode.VerifyCallback(Uri callback) at DotNetOpenAuth.OAuth2.ChannelElements.MessageValidationBindingElement.Proce ssIncomingMessage(IProtocolMessage message)
Looking at the source-code of DotNetOpenAuth.OAuth2.ChannelElements.AuthorizationCode.VerifyCallback I figured out what URI it was expecting, and I'm now able to get a response using the server-side flow. The response also contains a refresh_token that I'm about to test how works. However, there are one thing I don't like about this solution, and that is that I have to "give away" my secret to the public... I'm not sure what this signifies though, it's just the word "secret" that makes it sound like something I maybe shouldn't do...
Ok, for those of you who are wondering, DNOA supports refresh_tokens out of the box (I didn't need to do anything except switch to authorization_code instead of token request). The downside, as I said in my previous post is that I have to give away my secret key. I'm currently thinking of ways to solve this on the server-side, so that users going to my website in the browser; though *my website only* can get tokens without a client_secret beeing presented. This will probably be solvable through some antyforgery sessions, in combination with the token-request.
Good progress. As for a client secret, I take it you're saying that your
javascript client has to have a secret to get an authorization code, is
that right? If so, that's the bit that the OAuth 2 recent drafts recently
allowed to happen, and DNOA hasn't been updated to account for it yet.
Anonymous clients be allowed to be issued refresh tokens if it complies
with the required security of the host, which in this case it sounds like
you're happy with.
I want to call out that anonymous clients that can be issued refresh tokens
*can* lead to new security exploits. For example, if I can get your user
to enter their password just once, I can get a refresh token, and thereby
gain access to that user's data, and be immune to that user changing their
password in order to cancel my access. So you may want to establish some
kind of inactivity timeout for authorizations granted to anonymous clients
so that refresh tokens become unusable. You could also cause that any
password changes automatically also revoke authorizations to anonymous
clients.
--
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 Tue, Jul 24, 2012 at 11:07 PM, Aleksander Heintz <alxa...@alxandr.me>wrote:
> Ok, for those of you who are wondering, DNOA supports refresh_tokens out
> of the box (I didn't need to do anything except switch to
> authorization_code instead of token request). The downside, as I said in my
> previous post is that I have to give away my secret key. I'm currently
> thinking of ways to solve this on the server-side, so that users going to
> my website in the browser; though *my website only* can get tokens
> without a client_secret beeing presented. This will probably be solvable
> through some antyforgery sessions, in combination with the token-request.
> To post to this group, send email to dotnetopenid@googlegroups.com.
> To unsubscribe from this group, send email to
> dotnetopenid+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/dotnetopenid?hl=en.
I was thinking. What I have my server generate a refresh_token (doing the server-side OAuth2 flow to itself) during a Forms login? That wouldn't be any more insecure than normal websites (without API access). I don't even have to give the client the refresh_token, I can just store it in session and setup an endpoint for getting new access_tokens given that the refresh_token is stored in session. How would that be for safty measure?
> Also, I have no idea on how to withdraw refresh_tokens generated by DNOA,
nor do I know when users changes passwords or the likes, cause I use openID to login; though I do know what client's they have granted access to, and can give them the ability to withdraw that. That would make the "IsAuthorizationValid" return false.
Sent from my Windows Phone
------------------------------
From: Aleksander Heintz
Sent: 7/25/2012 10:20 PM
To: dotnetopenid@googlegroups.com
Subject: Re: [dotnetopenauth] OAuth2 roling expiration or refresh_token
I was thinking. What I have my server generate a refresh_token (doing the
server-side OAuth2 flow to itself) during a Forms login? That wouldn't be
any more insecure than normal websites (without API access). I don't even
have to give the client the refresh_token, I can just store it in session
and setup an endpoint for getting new access_tokens given that the
refresh_token is stored in session. How would that be for safty measure?
> Also, I have no idea on how to withdraw refresh_tokens generated by DNOA,
nor do I know when users changes passwords or the likes, cause I use openID
to login; though I do know what client's they have granted access to, and
can give them the ability to withdraw that. That would make the
"IsAuthorizationValid" return false.
-- You received this message because you are subscribed to the Google Groups
"DotNetOpenAuth" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/dotnetopenid/-/HvM1DahvbtIJ.
To post to this group, send email to dotnetopenid@googlegroups.com.
To unsubscribe from this group, send email to
dotnetopenid+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/dotnetopenid?hl=en.
With OAuth 1 you will have even more problems as the one of the things OAuth 2 added and Eran objected to was bearer tokens for a canvas app.
The code flow is intended for servers. If you have no security on the secret you may as well just use the token flow and make the tokens long lived. The user still has the ability to revoke them.
What a number of people like AOL are doing is keeping track of the session state and expiring the access token after the session expires and the user needs to log in again anyway.
John B.
On 2012-07-27, at 2:49 AM, Aleksander Heintz wrote:
> Seems maybe I should switch to oauth 1 and all my problems go away?
> -- > You received this message because you are subscribed to the Google Groups "DotNetOpenAuth" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/dotnetopenid/-/dlxd2VTJv24J.
> To post to this group, send email to dotnetopenid@googlegroups.com.
> To unsubscribe from this group, send email to dotnetopenid+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/dotnetopenid?hl=en.