Skip to content

Instantly share code, notes, and snippets.

@jacquescrocker
Created November 29, 2011 16:57
Show Gist options
  • Save jacquescrocker/1405523 to your computer and use it in GitHub Desktop.
Save jacquescrocker/1405523 to your computer and use it in GitHub Desktop.
# update token data from an OAuth2::AccessToken
def from_token!(token)
new_token_data = {
"token" => token.token,
"expires_in" => token.expires_in,
"expires_at" => token.expires_at,
}
# add back refresh token
if token.refresh_token.present?
new_token_data["refresh_token"] = token.refresh_token
else
new_token_data["refresh_token"] = self.token_data["refresh_token"]
end
if persisted?
update_document({
"$set" => {
"token_data" => new_token_data,
}
}, true)
else
self.token_data = new_token_data
end
new_token_data
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment