Created
January 17, 2012 20:12
-
-
Save jimsynz/1628625 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TokenExtension | |
def incoming(m,c) | |
if m['channel'] == '/service/requestToken' | |
token = if m['ext'] && m['ext']['token'] | |
Token.find_by_token(m['ext']['token']) | |
elsif by_client = Token.find_by_client_id(m['clientId']) | |
by_client | |
else | |
Token.new.tap { |t| t.client_id = m['clientId'] } | |
end | |
token.refresh if token.is_older_than 30.seconds | |
end | |
c.call(m) | |
end | |
def outgoing(m,c) | |
if m['channel'] == '/service/requestToken' | |
token = Token.find_by_client_id(m['clientId']) | |
if token && token.valid? | |
m['ext']['token'] = token.to_message | |
else | |
m['error'] = "Permission denied." | |
end | |
end | |
c.call(m) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment