Swiftpack.co -  elsesiy/GAppAuth as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
elsesiy/GAppAuth
Convenient Wrapper for AppAuth with Google Services written in Swift (>= 4).
.package(url: "https://github.com/elsesiy/GAppAuth.git", from: "1.6.0")

GAppAuth

pod License Twitter

This is a drop-in class to handle AppAuth with Google Services (iOS & macOS).

Installation via cocoapods

Just add this dependency to your Podfile:

pod GAppAuth

The transitive dependency to GTMAppAuth is added automatically.

Manually

Add GTMAppAuth dependency to your Podfile (Cocoapods) or copy the files manually to your project directory. Add GAppAuth.swift to your project and set-up you project as follows to use AppAuth with Google Services.

iOS

  1. Setup your project (APIs & Services -> Credentials -> Create Credentials -> OAuth Client ID -> iOS) at https://console.developers.google.com to retrieve ClientID and iOS scheme URL.
  2. Enable Google APIs as desired.
  3. Add ClientId and RedirectUri to your Info.plist:
<key>GAppAuth</key>
<dict>
    <key>RedirectUri</key>
    <string>com.googleusercontent.apps.YOUR-CLIENT-ID:/oauthredirect</string>
    <key>ClientId</key>
    <string>YOUR-CLIENT-ID.apps.googleusercontent.com</string>
</dict>
  1. Add custom URL-Scheme to your project:
<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>com.googleusercontent.apps.YOUR-CLIENT</string>
    </array>
  </dict>
</array>

macOS

  1. Setup your project (APIs & Services -> Credentials -> Create Credentials -> OAuth Client ID -> Other) at https://console.developers.google.com to retrieve ClientID and ClientSecret.
  2. Enable Google APIs as desired.
  3. Add ClientId, ClientSecret RedirectUri to your Info.plist:
<key>GAppAuth</key>
<dict>
    <key>RedirectUri</key>
    <string>com.googleusercontent.apps.YOUR-CLIENT-ID:/oauthredirect</string>
    <key>ClientId</key>
    <string>YOUR-CLIENT-ID.apps.googleusercontent.com</string>
    <key>ClientSecret</key>
    <string>YOUR-SECRET</string>
</dict>
  1. Add custom URL-Scheme to your project:
<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleTypeRole</key>
    <string>Editor</string>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>com.googleusercontent.apps.YOUR-CLIENT</string>
    </array>
  </dict>
</array>

Note: Make sure Sandboxing is turned off or properly configured, otherwise it's not possible to open the Browser window.

General

  1. In order to authorize for any Google Service, you'd need to append the respective scope to the authorization request via: GAppAuth.shared.appendAuthorizationRealm (i.e. kGTLRAuthScopeDrive for Google Drive access).
  2. From any UIViewController or NSViewController start the authorization workflow by calling GAppAuth.shared.authorize.
  3. You might want to retrieve any existing authorization upon start of the app which can be done via GAppAuth.shared.retrieveExistingAuthorizationState.
  4. There are two closures you can monitor in order to be notified about any changes stateChangeCallback or errors errorCallback.

Note: In case of a revoked access by the user, both callbacks will be called.

A good spot for 5. and 7. is the AppDelegate's didFinishLaunchingWithOptions.

Contribution

Feel free to create issues or open up a PR.

GitHub

link
Stars: 22
Last commit: 6 days ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Update dependencies & misc
24 weeks ago

This release incorporates the latest changes from GTMAppAuth and AppAuth SDKs as well as some minor syntax changes.

For more details see the Changelog.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API