-
Notifications
You must be signed in to change notification settings - Fork 279
When creating a Google client, you must choose to create a client ID for iOS.
You will receive a client-id with the form 9876-zyxwvu.apps.googleusercontent.com
, then use an OAuth2CodeGrant
with no client-secret and a redirect-uri in the form of com.googleusercontent.apps.9876-zyxwvu:/oauth
.
The Google API console will show the client id and redirect uri.
Don't forget to register it as an URL scheme in your app's Info.plist
!
var oauth2 = OAuth2CodeGrant(settings: [
"client_id": "9876-zyxwvu.apps.googleusercontent.com",
"authorize_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://www.googleapis.com/oauth2/v3/token",
"scope": "profile", // depends on the API you use
"redirect_uris": ["com.googleusercontent.apps.9876-zyxwvu:/oauth"],
])
When instantiating the OAuth2DataLoader
, set alsoIntercept403 = true
because Google returns status code 403 (instead of 401) for protected URLs such as https://www.googleapis.com/plus/v1/people/me
let loader = OAuth2DataLoader(oauth2: oauth2)
loader.alsoIntercept403 = true
Since v4, Google is no longer accepting an Other client ID; it detects the web view user agent and returns a 400 error if you are using “Other” (thanks @stefanhp!).