Skip to content

Commit

Permalink
Store creds in xcconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
leits committed Mar 29, 2022
1 parent aaca46b commit 4bc8c07
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
20 changes: 10 additions & 10 deletions MeetingBar/GCEventStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import GTMAppAuth
import PromiseKit
import SwiftyJSON

let GoogleClientNumber = ""
let GoogleClientSecret = ""
let GoogleClientNumber = Bundle.main.object(forInfoDictionaryKey: "GOOGLE_CLIENT_NUMBER") as! String
let GoogleClientSecret = Bundle.main.object(forInfoDictionaryKey: "GOOGLE_CLIENT_SECRET") as! String
let GoogleAuthKeychainName = Bundle.main.object(forInfoDictionaryKey: "GOOGLE_AUTH_KEYCHAIN_NAME") as! String

class GCEventStore: NSObject, EventStore, OIDExternalUserAgent {
static let kYourClientNumer = GoogleClientNumber
static let kIssuer = "https://accounts.google.com"
static let kClientID = "\(GoogleClientNumber).apps.googleusercontent.com"
static let kClientSecret = GoogleClientSecret
static let kRedirectURI = "com.googleusercontent.afpps.\(GoogleClientNumber):/oauthredirect"
static let kExampleAuthorizerKey = "REPLACE_BY_YOUR_AUTHORIZATION_KEY"
static let kRedirectURI = "com.googleusercontent.apps.\(GoogleClientNumber):/oauthredirect"
static let AuthKeychainName = GoogleAuthKeychainName

var currentAuthorizationFlow: OIDExternalUserAgentSession?

Expand Down Expand Up @@ -244,7 +244,7 @@ class GCEventStore: NSObject, EventStore, OIDExternalUserAgent {
let request = OIDAuthorizationRequest(configuration: config,
clientId: Self.kClientID,
clientSecret: Self.kClientSecret,
scopes: ["email", "https://www.googleapis.com/auth/calendar.readonly", "https://www.googleapis.com/auth/calendar.events.readonly"],
scopes: ["email", "https://www.googleapis.com/auth/calendar.calendarlist.readonly", "https://www.googleapis.com/auth/calendar.events.readonly"],
redirectURL: URL(string: Self.kRedirectURI)!,
responseType: OIDResponseTypeCode,
additionalParameters: nil)
Expand Down Expand Up @@ -280,21 +280,21 @@ class GCEventStore: NSObject, EventStore, OIDExternalUserAgent {
}

private func loadState() {
if let auth = GTMAppAuthFetcherAuthorization(fromKeychainForName: Self.kExampleAuthorizerKey) {
if let auth = GTMAppAuthFetcherAuthorization(fromKeychainForName: Self.AuthKeychainName) {
setAuthorization(auth: auth)
}
}

private func saveState() {
guard let auth = auth else {
GTMAppAuthFetcherAuthorization.removeFromKeychain(forName: Self.kExampleAuthorizerKey)
GTMAppAuthFetcherAuthorization.removeFromKeychain(forName: Self.AuthKeychainName)
return
}

if auth.canAuthorize() {
GTMAppAuthFetcherAuthorization.save(auth, toKeychainForName: Self.kExampleAuthorizerKey)
GTMAppAuthFetcherAuthorization.save(auth, toKeychainForName: Self.AuthKeychainName)
} else {
GTMAppAuthFetcherAuthorization.removeFromKeychain(forName: Self.kExampleAuthorizerKey)
GTMAppAuthFetcherAuthorization.removeFromKeychain(forName: Self.AuthKeychainName)
}
}

Expand Down
6 changes: 6 additions & 0 deletions MeetingBar/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>GOOGLE_CLIENT_SECRET</key>
<string>$(GOOGLE_CLIENT_SECRET)</string>
<key>GOOGLE_CLIENT_NUMBER</key>
<string>$(GOOGLE_CLIENT_NUMBER)</string>
<key>GOOGLE_AUTH_KEYCHAIN_NAME</key>
<string>$(GOOGLE_AUTH_KEYCHAIN_NAME)</string>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
Expand Down
3 changes: 3 additions & 0 deletions XCConfig/Project.xcconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
DEVELOPMENT_TEAM = KGH289N6T8
GOOGLE_CLIENT_NUMBER = REPLACE_BY_YOUR_GOOGLE_CLIENT_NUMBER
GOOGLE_CLIENT_SECRET = REPLACE_BY_YOUR_GOOGLE_CLIENT_SECRET
GOOGLE_AUTH_KEYCHAIN_NAME = REPLACE_BY_YOUR_GOOGLE_AUTH_KEYCHAIN_NAME
#include? "DevTeamOverride.xcconfig"

0 comments on commit 4bc8c07

Please sign in to comment.