Sha256: 49d33915e5e99bd0b777c1cbee3a4e7ac6312535a1f1e0e730150ab566a0737e
Contents?: true
Size: 1.18 KB
Versions: 2
Compression:
Stored size: 1.18 KB
Contents
# frozen_string_literal: true require 'googleauth' require 'googleauth/stores/file_token_store' require 'google/apis/calendar_v3' require 'fileutils' module Vgcal # for Google authorization class Authorizer def initialize @oob_uri = 'urn:ietf:wg:oauth:2.0:oob' @credentials_path = "#{Dir.home}/.vgcal/credentials.json" @token_path = "#{Dir.home}/.vgcal/token.yaml" @scope = Google::Apis::CalendarV3::AUTH_CALENDAR_READONLY end def credentials client_id = Google::Auth::ClientId.from_file @credentials_path token_store = Google::Auth::Stores::FileTokenStore.new file: @token_path authorizer = Google::Auth::UserAuthorizer.new client_id, @scope, token_store user_id = 'default' credentials = authorizer.get_credentials user_id if credentials.nil? url = authorizer.get_authorization_url base_url: @oob_uri puts "Open the following URL in the browser and enter the resulting code after authorization:\n#{url}" code = $stdin.gets credentials = authorizer.get_and_store_credentials_from_code( user_id: user_id, code: code, base_url: @oob_uri ) end credentials end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
vgcal-0.4.3 | lib/vgcal/google/authorizer.rb |
vgcal-0.4.2 | lib/vgcal/google/authorizer.rb |