//
// Copyright (C) 2025 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#if UNITY_ANDROID
namespace GooglePlayGames.BasicApi
{
using System;
using System.Collections.Generic;
using System.Linq;
///
/// Represents type-safe constants for the specific OAuth 2.0 authorization scopes used when
/// requesting server-side access to Play Games Services web APIs.
///
public enum AuthScope
{
///
/// See your primary Google Account email address.
///
EMAIL,
///
/// See your personal info, including any personal info you've made publicly available.
///
PROFILE,
///
/// Associate you with your personal info on Google.
///
OPEN_ID
}
///
/// Extensions for the AuthScope enum.
///
/// These extensions are used to converting between the AuthScope enum and its string
/// representation.
///
///
public static class AuthScopeExtensions
{
///
/// A map of AuthScope string values to their enum representations.
///
private static readonly Dictionary _stringToEnumMap =
new Dictionary
{
{ "EMAIL", AuthScope.EMAIL },
{ "PROFILE", AuthScope.PROFILE },
{ "OPEN_ID", AuthScope.OPEN_ID }
};
///
/// A map of AuthScope enum values to their string representations.
///
private static readonly Dictionary _enumToStringMap =
_stringToEnumMap.ToDictionary(pair => pair.Value, pair => pair.Key);
///
/// Returns the standard string representation of this OAuth 2.0 scope.
///
/// The AuthScope enum value.
/// The string value used to represent this scope.
/// If the provided AuthScope is not valid.
public static string GetValue(this AuthScope authScope)
{
if (!_enumToStringMap.ContainsKey(authScope))
{
throw new ArgumentException($"Invalid AuthScope: {authScope}");
}
return _enumToStringMap[authScope];
}
///
/// Returns the AuthScope enum value corresponding to the provided string.
///
/// The string value used to represent the scope.
/// The AuthScope enum value corresponding to the provided string.
/// If the provided string is not a valid AuthScope.
public static AuthScope FromValue(string value)
{
if (!_stringToEnumMap.ContainsKey(value))
{
throw new ArgumentException($"Invalid AuthScope: {value}");
}
return _stringToEnumMap[value];
}
}
}
#endif