Class: Skydrive::Oauth::Client
- Inherits:
-
Object
- Object
- Skydrive::Oauth::Client
- Defined in:
- lib/skydrive/oauth/client.rb
Overview
Oauth client class
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#callback_url ⇒ Object
Returns the value of attribute callback_url.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#oauth_client ⇒ Object
Returns the value of attribute oauth_client.
-
#scope ⇒ Object
Returns the value of attribute scope.
Instance Method Summary collapse
-
#authorize_url ⇒ String
Step 1: URL for OAuth2 authorization of Microsoft Live.
-
#get_access_token(code) ⇒ OAuth2::AccessToken
Step 2: Get access token after authorizing user.
-
#get_access_token_from_hash(token, opts = {}) ⇒ OAuth2::AccessToken
Alternate Step2: Make an access token from already available data one of :header, :body or :query.
-
#initialize(client_id, client_secret, callback_url, scope, opts = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(client_id, client_secret, callback_url, scope, opts = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/skydrive/oauth/client.rb', line 8 def initialize(client_id, client_secret, callback_url, scope, opts={}) @client_id = client_id @client_secret = client_secret @callback_url = callback_url @scope = scope ssl = opts.delete(:ssl) @options = { :site => 'https://login.live.com/', :authorize_url => "oauth20_authorize.srf?response_type=code&scope=#{scope}", :token_url => 'oauth20_token.srf', :parse_json => true}.merge(opts) @options[:connection_opts][:ssl] = ssl if ssl @oauth_client = OAuth2::Client.new(client_id, client_secret, @options) end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
7 8 9 |
# File 'lib/skydrive/oauth/client.rb', line 7 def access_token @access_token end |
#callback_url ⇒ Object
Returns the value of attribute callback_url.
7 8 9 |
# File 'lib/skydrive/oauth/client.rb', line 7 def callback_url @callback_url end |
#client_id ⇒ Object
Returns the value of attribute client_id.
7 8 9 |
# File 'lib/skydrive/oauth/client.rb', line 7 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
7 8 9 |
# File 'lib/skydrive/oauth/client.rb', line 7 def client_secret @client_secret end |
#oauth_client ⇒ Object
Returns the value of attribute oauth_client.
7 8 9 |
# File 'lib/skydrive/oauth/client.rb', line 7 def oauth_client @oauth_client end |
#scope ⇒ Object
Returns the value of attribute scope.
7 8 9 |
# File 'lib/skydrive/oauth/client.rb', line 7 def scope @scope end |
Instance Method Details
#authorize_url ⇒ String
Step 1: URL for OAuth2 authorization of Microsoft Live
26 27 28 |
# File 'lib/skydrive/oauth/client.rb', line 26 def oauth_client.auth_code.(:redirect_uri => callback_url) end |
#get_access_token(code) ⇒ OAuth2::AccessToken
Step 2: Get access token after authorizing user
33 34 35 |
# File 'lib/skydrive/oauth/client.rb', line 33 def get_access_token code @access_token = oauth_client.auth_code.get_token(code, :redirect_uri => callback_url) end |
#get_access_token_from_hash(token, opts = {}) ⇒ OAuth2::AccessToken
Alternate Step2: Make an access token from already available data one of :header, :body or :query
48 49 50 |
# File 'lib/skydrive/oauth/client.rb', line 48 def get_access_token_from_hash token, opts={} @access_token = OAuth2::AccessToken.new(@oauth_client, token, opts) end |