Class: Lita::Handlers::Gauth
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::Gauth
- Defined in:
- lib/lita/handlers/gauth.rb
Instance Method Summary collapse
- #auth_client ⇒ Object
- #auth_redir(req, resp) ⇒ Object
- #auth_root(req, resp) ⇒ Object
- #auth_save(req, resp) ⇒ Object
- #build_redir_url ⇒ Object
- #check_auth(msg) ⇒ Object
- #get_user_creds(user_id) ⇒ Object
- #request_auth(msg) ⇒ Object
- #save_creds(user_id, code) ⇒ Object
Instance Method Details
#auth_client ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/lita/handlers/gauth.rb', line 74 def auth_client @_auth_client ||=GoogleAuthBox::Client.new( client_id_hash: config.client_id_hash, scopes: config.scopes, data_file_path: config.data_file_path, base_uri: build_redir_url ) end |
#auth_redir(req, resp) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/lita/handlers/gauth.rb', line 40 def auth_redir(req, resp) attrs = { storage_key: 'lita_gauth_user_id', code: req.params["code"], base_url: build_redir_url } resp.body << render_template("auth_redir.html", attrs) end |
#auth_root(req, resp) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/lita/handlers/gauth.rb', line 49 def auth_root(req, resp) attrs = { "auth_redir_url": auth_client.get_auth_url, "user_id": JSON.parse(req.env["router.params"][:id]), "storage_key": "lita_gauth_user_id" } resp.body << render_template('auth_root.html', attrs) end |
#auth_save(req, resp) ⇒ Object
59 60 61 62 63 |
# File 'lib/lita/handlers/gauth.rb', line 59 def auth_save(req, resp) user_id = JSON.parse(req.env['router.params'][:user_id]) save_creds user_id, req.params["code"] resp.write MultiJson.dump(msg: "ok") end |
#build_redir_url ⇒ Object
70 71 72 |
# File 'lib/lita/handlers/gauth.rb', line 70 def build_redir_url "#{config.base_domain}#{config.oauth_redir_path}" end |
#check_auth(msg) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/lita/handlers/gauth.rb', line 26 def check_auth(msg) credentials = get_user_creds msg.user.id if credentials.nil? url = auth_client.get_auth_url msg.reply "You are not authed" msg.reply "Please click the following link to register with the goog: #{url}" end end |
#get_user_creds(user_id) ⇒ Object
22 23 24 |
# File 'lib/lita/handlers/gauth.rb', line 22 def get_user_creds(user_id) auth_client.get_creds user_id end |
#request_auth(msg) ⇒ Object
65 66 67 68 |
# File 'lib/lita/handlers/gauth.rb', line 65 def request_auth(msg) url = "#{config.base_domain}/auth-root" msg.reply "Click the followin link to do the thing! #{url}" end |
#save_creds(user_id, code) ⇒ Object
36 37 38 |
# File 'lib/lita/handlers/gauth.rb', line 36 def save_creds(user_id, code) auth_client.save_creds user_id, code end |