Skip to content
This repository has been archived by the owner on Aug 25, 2020. It is now read-only.

Expired token and other error handling #31

Closed
pacovell opened this issue Aug 7, 2012 · 1 comment
Closed

Expired token and other error handling #31

pacovell opened this issue Aug 7, 2012 · 1 comment

Comments

@pacovell
Copy link
Contributor

pacovell commented Aug 7, 2012

I need to have a way to customize handling of expired tokens. Right now this is handled in server.rb:264:


        if token
          begin
            access_token = AccessToken.from_token(token)
            raise InvalidTokenError if access_token.nil? || access_token.revoked
            raise ExpiredTokenError if access_token.expires_at && access_token.expires_at <= Time.now.to_i
            request.env["oauth.access_token"] = token

            request.env["oauth.identity"] = access_token.identity
            access_token.access!
            logger.info "RO2S: Authorized #{access_token.identity}" if logger
          rescue OAuthError=>error
            #5.2.  The WWW-Authenticate Response Header Field
            logger.info "RO2S: HTTP authorization failed #{error.code}" if logger
            return unauthorized(request, error)
          rescue =>ex
            logger.info "RO2S: HTTP authorization failed #{ex.message}" if logger
            return unauthorized(request)
          end

I can think of two ways to easily handle this: (1) A la cancan authorization, we allow the exception to propagate instead of rescuing it, and then it can be caught at a higher layer and managed; (2) insert some kind of handler hook that allows structuring of a response.

Specifically, in this case I am using the authorization in a session with a normal web browser, and so I need to redirect the user to a login page when the token expires.

Any thoughts on better / good ways to solve this?

@pacovell
Copy link
Contributor Author

pacovell commented Aug 7, 2012

False alarm, this was fixed by the expired token pull request in issue #17 (fixed 2.7.0 release). Pulled it in and we're good to go.

denyago added a commit to denyago/rack-oauth2-server that referenced this issue Aug 30, 2012
@assaf assaf closed this as completed Feb 18, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants