Skip to content

Commit

Permalink
Add Oauth Scopes to PlayGamesClientConfiguration
Browse files Browse the repository at this point in the history
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
  • Loading branch information
paulsalameh authored Jul 26, 2016
1 parent d949b45 commit 98ba1f1
Showing 1 changed file with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="PlayGamesClientConfiguration.cs" company="Google Inc.">
// <copyright file="PlayGamesClientConfiguration.cs" company="Google Inc.">
// Copyright (C) 2014 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -19,6 +19,7 @@ namespace GooglePlayGames.BasicApi
{
using GooglePlayGames.BasicApi.Multiplayer;
using GooglePlayGames.OurUtils;
using System.Collections.Generic;

/// <summary>
/// Provides configuration for <see cref="PlayGamesPlatform"/>. If you wish to use either Saved
Expand All @@ -44,6 +45,11 @@ public struct PlayGamesClientConfiguration
/// Flag indicating to request use of a player's Google+ social graph.
/// </summary>
private readonly bool mRequireGooglePlus;

/// <summary>
/// Array of scopes to be requested from user. None is considered as 'games_lite'.
/// </summary>
private readonly string[] mScopes;

/// <summary>
/// The invitation delegate.
Expand Down Expand Up @@ -72,6 +78,7 @@ private PlayGamesClientConfiguration(Builder builder)
this.mMatchDelegate = builder.GetMatchDelegate();
this.mPermissionRationale = builder.GetPermissionRationale();
this.mRequireGooglePlus = builder.HasRequireGooglePlus();
this.mScopes = builder.getScopes();
}

/// <summary>
Expand Down Expand Up @@ -99,6 +106,18 @@ public bool RequireGooglePlus
return mRequireGooglePlus;
}
}

/// <summary>
/// Gets a array of scopes to be requested from the user.
/// </summary>
/// <value>String array of scopes.</value>
public string[] Scopes
{
get
{
return mScopes;
}
}

/// <summary>
/// Gets the invitation delegate.
Expand Down Expand Up @@ -150,6 +169,11 @@ public class Builder
/// The flag to request Google+. Default is false.
/// </summary>
private bool mRequireGooglePlus = false;

/// <summary>
/// The scopes to request from the user. Default is none.
/// </summary>
private List<string> mScopes = null;

/// <summary>
/// The invitation delegate. Default is a no-op;
Expand Down Expand Up @@ -180,7 +204,7 @@ public Builder EnableSavedGames()
mEnableSaveGames = true;
return this;
}

/// <summary>
/// Requests use of the player's Google+ social graph.
/// </summary>
Expand All @@ -196,6 +220,24 @@ public Builder RequireGooglePlus()
return this;
}

/// <summary>
/// Requests an Oauth scope from the user.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
/// <returns>The builder.</returns>
public Builder AddOauthScope(string scope)
{
if (mScopes == null) mScopes = new List<string>();
mScopes.Add(scope);
return this;
}

/// <summary>
/// Adds the invitation delegate. This is called when an invitation
/// is received.
Expand Down Expand Up @@ -251,7 +293,7 @@ internal bool HasEnableSaveGames()
{
return mEnableSaveGames;
}

/// <summary>
/// Determines whether this instance has Google+ required.
/// </summary>
Expand All @@ -261,6 +303,14 @@ internal bool HasRequireGooglePlus()
return mRequireGooglePlus;
}

/// <summary>
/// Gets the Oauth scopes to be requested from the user.
/// </summary>
/// <returns>String array of scopes.</returns>
internal string[] getScopes() {
return mScopes == null? new string[0] : mScopes.ToArray();
}

/// <summary>
/// Gets the match delegate.
/// </summary>
Expand Down

0 comments on commit 98ba1f1

Please sign in to comment.