Google Sign In Plugin: How do you add scopes for ios?

In the Google Sign In plugin documentation I see that the googleSignIn.init() method allows you to supply scopes for android but not iOS.

I see that there is a method to request scopes for a signed in user (googleSignIn.requestScope(scope, listener)), but after it is invoked it prompts the user to sign in again then after the user signs in it causes the app to crash.

In the console I noticed this error message which may be relevant - "SecDbKeychainItemV7: item’s secret data exceeds reasonable size (5158 bytes) "

I have modified the main.lua file of the sample project by including an additional button to request scope:

local googleSignIn = require "plugin.googleSignIn"
local json = require("json")

local widget = require("widget")

googleSignIn.init({
	ios={
		clientId = "replace",
		scopes = {"https://www.googleapis.com/auth/drive.file"}
	},
	android={
		clientId = "replace",
		scopes = {"https://www.googleapis.com/auth/drive.file"}
	}
})
googleSignIn.silentSignIn(function (e)
  if (e.isError) then
  	print(e.error)
  else
   print("you are signed in")
 end
end)

local bg = display.newRect( display.contentCenterX, display.contentCenterY, display.actualContentWidth, display.actualContentHeight )
bg:setFillColor( 0,0,1 )

local title = display.newText( "Google Sign In", display.contentCenterX, 40, native.systemFontBold ,30)


function googleListener(event)
	if (event.isError == true) then
		native.showAlert("Error Sign In", event.error, {"Ok"})
	elseif(event.status == "cancelled") then
		native.showAlert("Sign In Cancelled", json.encode(event), {"Ok"})
	elseif(event.status == "signed in") then
		native.showAlert("Signed In", json.encode(event), {"Ok"})
	elseif(event.status == "signed out") then
		native.showAlert("Signed Out", json.encode(event), {"Ok"})
	else
		native.showAlert(event.status, json.encode(event), {"Ok"})
	end
end

function signIn_onEvent(event)
	if(event.phase == "ended")then
		googleSignIn.signIn(googleListener)
	end
end

local signIn = widget.newButton( {
	label = "Sign In",
	fontSize = 20,
	labelColor = { default={ 1, 1, 1 }, over={ 0, 0, 0, 0.5 } },
	x = display.contentCenterX,
	y = display.contentCenterY,
	onEvent = signIn_onEvent
} )

function signOut_onEvent(event)
	if(event.phase == "ended")then
        googleSignIn.disconnect(googleListener)
        googleSignIn.signOut(googleListener)
	end
end

local signOut = widget.newButton( {
	label = "Sign Out/Disconnect",
	fontSize = 20,
	labelColor = { default={ 1, 1, 1 }, over={ 0, 0, 0, 0.5 } },
	x = display.contentCenterX,
	y = display.contentCenterY+50,
	onEvent = signOut_onEvent
} )

function requestScope_onEvent(event)
	if(event.phase == "ended")then
		--googleSignIn.requestScope({"https://www.googleapis.com/auth/drive.file"} , googleListener)
		googleSignIn.requestScope({"https://www.googleapis.com/auth/drive.file"} , {googleListener})
	end
end

local requestScope = widget.newButton( {
	label = "Request Scope (drive.file)",
	fontSize = 20,
	labelColor = { default={ 1, 1, 1 }, over={ 0, 0, 0, 0.5 } },
	x = display.contentCenterX,
	y = display.contentCenterY+100,
	onEvent = requestScope_onEvent
} )

function getUser_onEvent(event)
	if(event.phase == "ended")then
		googleSignIn.getCurrentUser(googleListener)
	end
end

local getUser = widget.newButton( {
	label = "Get Current User",
	fontSize = 20,
	labelColor = { default={ 1, 1, 1 }, over={ 0, 0, 0, 0.5 } },
	x = display.contentCenterX,
	y = display.contentCenterY+150,
	onEvent = getUser_onEvent
} )

@Scott_Harrison Any thoughts on this issue?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.