// // 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; /// /// Represents the response received from Play Games Services when requesting a server-side OAuth 2.0 /// authorization code for the signed-in player. /// public class AuthResponse { private readonly string _authCode; private readonly List _grantedScopes; /// /// Constructs an AuthResponse with the provided granted scopes and authentication code. /// /// The authentication code. /// A list of AuthScope objects representing the granted scopes. /// If grantedScopes is null. public AuthResponse(string authCode, List grantedScopes) { if (grantedScopes == null) { throw new ArgumentNullException(nameof(grantedScopes), "Granted scopes list cannot be null"); } _authCode = authCode; _grantedScopes = grantedScopes; } /// /// Gets the list of AuthScope permissions that the user has granted. /// /// /// A list of the AuthScope permissions the user explicitly granted consent for (or /// previously approved). The list will be empty if the user declines consent and none of the /// requested AuthScope were previously granted. /// /// A List of AuthScope objects, representing the granted permissions. public List GetGrantedScopes() { return _grantedScopes; } /// /// Gets the OAuth 2.0 authorization code. /// /// /// This code is a short-lived credential that should be sent securely to your server to be /// exchanged for an access token and conditionally a refresh token. /// /// A string containing the OAuth 2.0 authorization code. public string GetAuthCode() { return _authCode; } public override bool Equals(object obj) { if (ReferenceEquals(this, obj)) { return true; } if (obj == null || GetType() != obj.GetType()) { return false; } var other = (AuthResponse)obj; return _grantedScopes.Equals(other._grantedScopes) && _authCode == other._authCode; } public override int GetHashCode() { return HashCode.Combine(_grantedScopes, _authCode); } public override string ToString() { string grantedScopesText = _grantedScopes.Count > 0 ? string.Join(", ", _grantedScopes.ToArray()) : "[]"; return $"AuthResponse {{ grantedScopes = {grantedScopesText}, authCode = {_authCode} }}"; } } } #endif