Skip to content

Storing and Restoring an Access Token

Created by: tomrossi7

When storing an access token, I have to first convert it to a hash and then serialize it to the database. Included in that hash is the expires_at -- not the expires_in since it will be meaningless in the future. When I reinstantiate the token from the hash, it ignores the expires_at attribute? Shouldn't that be the absolute time that the token expires, while the expires_in is relative and should be recalculated?

To store the token:

oauth2_token_hash = {:access_token => token.token, :refresh_token => token.refresh_token, :expires_at => token.expires_at}

To restore the token:

OAuth2::AccessToken.from_hash(oauth2_client, oauth2_token_hash)
Edited by Peter Boling