class Naver::Oauth
Public Class Methods
new(redirect_uri: Naver.redirect_uri)
click to toggle source
Create a OAuth object. @param redirect_uri [String] OAuth redirect_uri
# File lib/naver/oauth.rb, line 5 def initialize(redirect_uri: Naver.redirect_uri) @client_id = Naver.client_id @client_secret = Naver.client_secret @oauth_base_uri = Configuration::DEFAULT_OAUTH_BASE_URI @redirect_uri = redirect_uri headers = { user_agent: Configuration::DEFAULT_USER_AGENT } @oauth = OAuth2::Client.new(@client_id, @client_secret, site: @oauth_base_uri, authorize_url: "/oauth2.0/authorize", token_url: "/oauth2.0/token", headers: headers) do |http| http.request :multipart http.request :url_encoded http.response :logger if Naver.debug http.adapter :net_http end end
Public Instance Methods
create_and_assign_token(token_extract)
click to toggle source
Create and assign new access token from extracted token. To be used with extract_token
to reauthorize app without api call. @param token_extract [Hash] OAuth token hash from extract_token
. @return [OAuth2::AccessToken, nil] New access token object.
# File lib/naver/oauth.rb, line 50 def create_and_assign_token(token_extract) unless token_extract.nil? @oauth_token = OAuth2::AccessToken.from_hash(@oauth, token_extract) end end
extract_token()
click to toggle source
Extract hash with OAuth token attributes. Extracted token attributes can be used with create_and_assign_token
to prevent the need for reauthorization. @return [Hash, nil] @oauth_token converted to a hash.
# File lib/naver/oauth.rb, line 42 def extract_token @oauth_token.to_hash if @oauth_token end
Private Instance Methods
refresh_token!()
click to toggle source
# File lib/naver/oauth.rb, line 58 def refresh_token! return unless @oauth_token.expired? @oauth_token = @oauth_token.refresh_token end