Class: Modgen::Session::Oauth2
Instance Attribute Summary collapse
-
#authorize_url ⇒ Object
readonly
Returns the value of attribute authorize_url.
Class Method Summary collapse
- .authorize(auth_code) ⇒ Object
- .config ⇒ Object
-
.get_authorize_code ⇒ Object
Automaticaly open autorization url a waiting for callback.
-
.start ⇒ Object
Start session.
Instance Method Summary collapse
- #authorize(auth_code) ⇒ Object
- #execute(request) ⇒ Object
-
#initialize ⇒ Oauth2
constructor
A new instance of Oauth2.
Constructor Details
Instance Attribute Details
#authorize_url ⇒ Object (readonly)
Returns the value of attribute authorize_url.
74 75 76 |
# File 'lib/modgen/session/oauth2.rb', line 74 def @authorize_url end |
Class Method Details
.authorize(auth_code) ⇒ Object
26 27 28 |
# File 'lib/modgen/session/oauth2.rb', line 26 def self.(auth_code) Modgen::Session.get.(auth_code) end |
.config ⇒ Object
7 8 9 |
# File 'lib/modgen/session/oauth2.rb', line 7 def self.config Modgen.config end |
.get_authorize_code ⇒ Object
Automaticaly open autorization url a waiting for callback. Launchy gem is required
Steps: 1) create server 2) launch browser and redirect to google api 3) confirm and modgen redirect to localhost 4) server get code and start session 5) close server - you are login
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/modgen/session/oauth2.rb', line 39 def self. require "socket" # tcp server uri = URI(Modgen::OAUTH2_REDIRECT_URI) webserver = TCPServer.new(uri.host, 0) # start webserver # port=0 - automatically choose free port uri.port = webserver.addr[1] # get choosen port Launchy.open(Modgen::Session.get.) session = webserver.accept # parse header for query. request = session.gets.gsub(/GET\ \//, '').gsub(/\ HTTP.*/, '') request = Hash[URI.decode_www_form(URI(request).query)] # failure login to_return = false = "You have not been logged. Please try again." if Modgen::Session.get.(request['code']) = "You have been successfully logged. Now you can close the browser." to_return = true end session.write() session.close return to_return end |
Instance Method Details
#authorize(auth_code) ⇒ Object
82 83 84 85 86 |
# File 'lib/modgen/session/oauth2.rb', line 82 def (auth_code) @auth_code = auth_code @token = @client.auth_code.get_token(auth_code) end |
#execute(request) ⇒ Object
88 89 90 |
# File 'lib/modgen/session/oauth2.rb', line 88 def execute(request) end |