Contents

darrarski/swift-google-drive-client

Basic Google Drive HTTP API client that does not depend on Google's SDK.

πŸ“– Usage

Use Swift Package Manager to add the GoogleDriveClient library as a dependency to your project.

Configure OAuth 2.0 Client ID using Google Cloud Console. Use iOS application type.

Configure your application so that it can handle sign-in redirects. For an iOS app, you can do it by adding or modifying CFBundleURLTypes in Info.plist:

<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleTypeRole</key>
    <string>Editor</string>
    <key>CFBundleURLName</key>
    <string></string>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>com.googleusercontent.apps.1234-abcd</string>
    </array>
  </dict>
</array>

Create the client:

import GoogleDriveClient

let client = GoogleDriveClient.Client.live(
  config: .init(
    clientID: "1234-abcd.apps.googleusercontent.com",
    authScope: "https://www.googleapis.com/auth/drive",
    redirectURI: "com.googleusercontent.apps.1234-abcd://"
  )
)

Make sure the redirectURI contains the scheme defined earlier.

The package provides a basic implementation for storing vulnerable data securely in the keychain. Optionally, you can provide your own, custom implementation of a keychain, instead of using the default one.

import GoogleDriveClient

let keychain = GoogleDriveClient.Keychain(
  loadCredentials: { () async -> GoogleDriveClient.Credentials? in
    // load from secure storage and return
  },
  saveCredentials: { (GoogleDriveClient.Credentials) async -> Void in
    // save in secure storage
  },
  deleteCredentials: { () async -> Void in
    // delete from secure storage
  }
)
let client = GoogleDriveClient.Client.live(
  config: .init(...),
  keychain: keychain
)

▢️ Example

This repository contains an example iOS application built with SwiftUI.

  • Open GoogleDriveClient.xcworkspace in Xcode.
  • Example source code is contained in the Example Xcode project.
  • Run the app using the GoogleDriveClientExampleApp build scheme.
  • The "Example" tab provides UI that uses GoogleDriveClient library.
  • The "Console" tab provides UI for browsing application logs and HTTP requests.

The example app uses Dependencies to manage its own internal dependencies. For more information about the Dependencies library check out official documentation.

πŸ› Project structure

GoogleDriveClient (Xcode Workspace)
 β”œβ”€ swift-google-drive-client (Swift Package)
 |   └─ GoogleDriveClient (Library)
 └─ Example (Xcode Project)
     └─ GoogleDriveClientExampleApp (iOS Application)

πŸ›  Develop

  • Use Xcode (version β‰₯ 14.3.1).
  • Clone the repository or create a fork & clone it.
  • Open GoogleDriveClient.xcworkspace in Xcode.
  • Use the GoogleDriveClient scheme for building the library and running unit tests.
  • If you want to contribute, create a pull request containing your changes or bug fixes. Make sure to include tests for new/updated code.

β˜•οΈ Do you like the project?

<a href="https://www.buymeacoffee.com/darrarski" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" height="60" width="217" style="height: 60px !important;width: 217px !important;" ></a>

πŸ“„ License

Copyright Β© 2023 Dariusz Rybicki Darrarski

License: MIT

Package Metadata

Repository: darrarski/swift-google-drive-client

Stars: 34

Forks: 8

Open issues: 3

Default branch: main

Primary language: swift

License: MIT

Topics: cloud-file-system, cloud-files, google-drive, google-drive-api, google-drive-client, oauth2, swift, swift-package-manager

README: README.md