Class: Imap::Backup::Configuration::GmailOauth2

Inherits:
Object
  • Object
show all
Defined in:
lib/imap/backup/configuration/gmail_oauth2.rb

Constant Summary collapse

"GMail OAuth2 Setup\n\nYou need to authorize imap_backup to get access to your email.\nTo do so, please follow the instructions here:\n\nhttps://github.com/joeyates/imap-backup/blob/main/docs/setting-up-gmail.md\n\n".freeze
GMAIL_READ_SCOPE =
"https://mail.google.com/".freeze
OOB_URI =
"urn:ietf:wg:oauth:2.0:oob".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account) ⇒ GmailOauth2

Returns a new instance of GmailOauth2.



22
23
24
# File 'lib/imap/backup/configuration/gmail_oauth2.rb', line 22

def initialize()
  @account = 
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



18
19
20
# File 'lib/imap/backup/configuration/gmail_oauth2.rb', line 18

def 
  @account
end

#client_idObject (readonly)

Returns the value of attribute client_id.



19
20
21
# File 'lib/imap/backup/configuration/gmail_oauth2.rb', line 19

def client_id
  @client_id
end

#client_secretObject (readonly)

Returns the value of attribute client_secret.



20
21
22
# File 'lib/imap/backup/configuration/gmail_oauth2.rb', line 20

def client_secret
  @client_secret
end

Instance Method Details

#runObject



26
27
28
29
30
31
32
33
34
35
36
37
38
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
# File 'lib/imap/backup/configuration/gmail_oauth2.rb', line 26

def run
  Kernel.system("clear")
  Kernel.puts BANNER

  keep = if token.valid?
    highline.agree("Use existing client info?")
  else
    false
  end

  if keep
    @client_id = token.client_id
    @client_secret = token.client_secret
  else
    @client_id = highline.ask("client_id: ")
    @client_secret = highline.ask("client_secret: ")
  end

  Kernel.puts "\n    Open the following URL in your browser\n\n    \#{authorization_url}\n\n    Then copy the success code\n\n  MESSAGE\n\n  @code = highline.ask(\"success code: \")\n  @credentials = authorizer.get_and_store_credentials_from_code(\n    user_id: email, code: @code, base_url: OOB_URI\n  )\n\n  raise \"Failed\" if !@credentials\n\n  new_token = JSON.parse(token_store.load(email))\n  new_token[\"client_secret\"] = client_secret\n  new_token.to_json\nend\n"