Class: Tahweel::Authorizer
- Inherits:
-
Object
- Object
- Tahweel::Authorizer
- Defined in:
- lib/tahweel/authorizer.rb
Overview
Handles the OAuth 2.0 Authorization flow for the application.
This class is responsible for:
-
Determining the secure storage path for the token.
-
Checking if valid credentials already exist.
-
Initiating the OAuth 2.0 flow via a local web server if needed.
-
Exchanging the authorization code for credentials and persisting them.
Constant Summary collapse
- CLIENT_ID =
"512416833080-hptj9s5r92pjmdgigrcugbp40ng9isvj.apps.googleusercontent.com"- CLIENT_SECRET =
"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"- PORT =
3027- REDIRECT_URI =
"http://localhost:#{PORT}/".freeze
- USER_ID =
"default"
Class Method Summary collapse
-
.authorize ⇒ Google::Auth::UserRefreshCredentials
Convenience class method to authorize the user.
-
.clear_credentials ⇒ void
Convenience class method to clear stored credentials.
Instance Method Summary collapse
-
#authorize ⇒ Google::Auth::UserRefreshCredentials
Performs the authorization process.
-
#clear_credentials ⇒ void
Clears the stored credentials file.
-
#initialize ⇒ Authorizer
constructor
Initializes a new Authorizer instance.
Constructor Details
#initialize ⇒ Authorizer
Initializes a new Authorizer instance. Sets up the Google Auth client and token store.
41 42 43 44 45 |
# File 'lib/tahweel/authorizer.rb', line 41 def initialize @client_id = Google::Auth::ClientId.new(CLIENT_ID, CLIENT_SECRET) @token_store = Google::Auth::Stores::FileTokenStore.new(file: token_path) = Google::Auth::UserAuthorizer.new(@client_id, Google::Apis::DriveV3::AUTH_DRIVE_FILE, @token_store) end |
Class Method Details
.authorize ⇒ Google::Auth::UserRefreshCredentials
Convenience class method to authorize the user. Instantiates the Authorizer and calls #authorize.
32 |
# File 'lib/tahweel/authorizer.rb', line 32 def self. = new. |
.clear_credentials ⇒ void
This method returns an undefined value.
Convenience class method to clear stored credentials.
37 |
# File 'lib/tahweel/authorizer.rb', line 37 def self.clear_credentials = new.clear_credentials |
Instance Method Details
#authorize ⇒ Google::Auth::UserRefreshCredentials
Performs the authorization process. Checks for existing valid credentials; if none are found, initiates the OAuth flow.
51 52 53 54 55 56 |
# File 'lib/tahweel/authorizer.rb', line 51 def credentials = .get_credentials(USER_ID) return credentials if credentials perform_oauth_flow end |
#clear_credentials ⇒ void
This method returns an undefined value.
Clears the stored credentials file.
61 62 63 64 65 66 |
# File 'lib/tahweel/authorizer.rb', line 61 def clear_credentials path = token_path return unless File.exist?(path) File.delete(path) end |