我已根据以下内容设置了GPPSignInButton:
https://developers.google.com/+/mobile/ios/sign-in#enable_server-side_api_access_for_your_app
let googleSignIn = GPPSignIn.sharedInstance()
googleSignIn.clientID = GoogleClientID
googleSignIn.attemptSSO = true
googleSignIn.homeServerClientID = GoogleServerClientID
googleSignIn.scopes = ["https://www.googleapis.com/auth/plus.login", "https://www.googleapis.com/auth/plus.profile.emails.read"]
googleSignIn.delegate = self
googleSignInButton.colorScheme = kGPPSignInButtonColorSchemeLight
googleSignInButton.style = kGPPSignInButtonStyleWide
用户首次登录时,它会要求正确的权限并返回
idToken
,该令牌将被转发到服务器并交换为access_token/refresh_token。但是,在调用
GPPSignIn.sharedInstance().signOut()
之后,再次登录将始终要求“具有离线访问权限”。我已经阅读了一些其他SO帖子,其中大多数引用了URL参数“approval_prompt”和“access_type”。鉴于我正在使用iOS SDK,我无法设置这些参数。
应用程序在Web视图中路由到的URL是:
https://accounts.google.com/o/oauth2/auth?gpsdk=1.7.1&audience=<server-client-id>&response_type=code&verifier=94014002&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fplus.login%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fplus.profile.emails.read&gpbtn=1.1&hl=en&redirect_uri=<redirect_uri>&client_id=<client-id>&state=702574
我在服务器端使用了相同的范围(“login”和“email”),但我无法弄清楚还需要做什么,以便它不会总是要求获得离线访问权限。