From 98ba1f173583a90c3c7f3812b183e6800059c101 Mon Sep 17 00:00:00 2001 From: PS Date: Tue, 26 Jul 2016 11:59:41 +0300 Subject: [PATCH] Add Oauth Scopes to PlayGamesClientConfiguration Adds option to add Oauth scopes to be requested by user, like 'profile' and 'email'. Not adding scopes will not allow server to exchange auth code with id_token. I will also update Platforms/Native/NativeClient.cs --- .../BasicApi/PlayGamesClientConfiguration.cs | 56 ++++++++++++++++++- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/source/PluginDev/Assets/GooglePlayGames/BasicApi/PlayGamesClientConfiguration.cs b/source/PluginDev/Assets/GooglePlayGames/BasicApi/PlayGamesClientConfiguration.cs index ceab40fa2..993f78e9a 100644 --- a/source/PluginDev/Assets/GooglePlayGames/BasicApi/PlayGamesClientConfiguration.cs +++ b/source/PluginDev/Assets/GooglePlayGames/BasicApi/PlayGamesClientConfiguration.cs @@ -1,4 +1,4 @@ -// +// // Copyright (C) 2014 Google Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,6 +19,7 @@ namespace GooglePlayGames.BasicApi { using GooglePlayGames.BasicApi.Multiplayer; using GooglePlayGames.OurUtils; + using System.Collections.Generic; /// /// Provides configuration for . If you wish to use either Saved @@ -44,6 +45,11 @@ public struct PlayGamesClientConfiguration /// Flag indicating to request use of a player's Google+ social graph. /// private readonly bool mRequireGooglePlus; + + /// + /// Array of scopes to be requested from user. None is considered as 'games_lite'. + /// + private readonly string[] mScopes; /// /// The invitation delegate. @@ -72,6 +78,7 @@ private PlayGamesClientConfiguration(Builder builder) this.mMatchDelegate = builder.GetMatchDelegate(); this.mPermissionRationale = builder.GetPermissionRationale(); this.mRequireGooglePlus = builder.HasRequireGooglePlus(); + this.mScopes = builder.getScopes(); } /// @@ -99,6 +106,18 @@ public bool RequireGooglePlus return mRequireGooglePlus; } } + + /// + /// Gets a array of scopes to be requested from the user. + /// + /// String array of scopes. + public string[] Scopes + { + get + { + return mScopes; + } + } /// /// Gets the invitation delegate. @@ -150,6 +169,11 @@ public class Builder /// The flag to request Google+. Default is false. /// private bool mRequireGooglePlus = false; + + /// + /// The scopes to request from the user. Default is none. + /// + private List mScopes = null; /// /// The invitation delegate. Default is a no-op; @@ -180,7 +204,7 @@ public Builder EnableSavedGames() mEnableSaveGames = true; return this; } - + /// /// Requests use of the player's Google+ social graph. /// @@ -196,6 +220,24 @@ public Builder RequireGooglePlus() return this; } + /// + /// Requests an Oauth scope from the user. + /// + /// + /// Not setting one will default to 'games_lite' and will not show a consent + /// dialog to the user. Valid examples are 'profile' and 'email'. + /// Full list: https://developers.google.com/identity/protocols/googlescopes + /// To exchange the auth code with an id_token (or user id) on your server, + /// you must add at least one scope. + /// + /// The builder. + public Builder AddOauthScope(string scope) + { + if (mScopes == null) mScopes = new List(); + mScopes.Add(scope); + return this; + } + /// /// Adds the invitation delegate. This is called when an invitation /// is received. @@ -251,7 +293,7 @@ internal bool HasEnableSaveGames() { return mEnableSaveGames; } - + /// /// Determines whether this instance has Google+ required. /// @@ -261,6 +303,14 @@ internal bool HasRequireGooglePlus() return mRequireGooglePlus; } + /// + /// Gets the Oauth scopes to be requested from the user. + /// + /// String array of scopes. + internal string[] getScopes() { + return mScopes == null? new string[0] : mScopes.ToArray(); + } + /// /// Gets the match delegate. ///