这是一个用于处理与 Google Services 相关的 AppAuth 的即插即用类(iOS & macOS)。
只需将此依赖项添加到您的 Podfile 中
pod GAppAuth
到 GTMAppAuth 的传递依赖会自动添加。
将 GTMAppAuth
依赖项添加到您的 Podfile (Cocoapods) 中,或者手动将文件复制到您的项目目录。将 GAppAuth.swift
添加到您的项目,并按如下方式设置您的项目以使用 AppAuth 与 Google Services。
<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>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.YOUR-CLIENT</string>
</array>
</dict>
</array>
<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>
<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>
注意: 确保 Sandboxing 已关闭或已正确配置,否则无法打开浏览器窗口。
GAppAuth.shared.appendAuthorizationRealm
将相应的 scope 附加到授权请求中(例如,用于访问 Google Drive 的 kGTLRAuthScopeDrive)。UIViewController
或 NSViewController
中,通过调用 GAppAuth.shared.authorize
启动授权工作流程。GAppAuth.shared.retrieveExistingAuthorizationState
来完成。stateChangeCallback
或错误 errorCallback
。注意: 如果用户撤销了访问权限,这两个回调都会被调用。
欢迎创建 issue 或打开 PR。