/// <summary> /// Returns a scope definition including default scopes and api scopes /// </summary> /// <param name="apiScopes">Enum flags for API scopes.</param> /// <param name="scopes">Default scopes that are added </param> /// <returns></returns> public static string GetScopes(ApiScopes apiScopes, DefaultScopes scopes = DefaultScopes.UserDefault) { var list = GetDefaultScopes(scopes); if (apiScopes.HasFlag(ApiScopes.SystemApiFullAccess)) { list.Add(SystemApiFullAccess); } else if (apiScopes.HasFlag(ApiScopes.SystemApiReadOnly)) { list.Add(SystemApiReadOnly); } if (apiScopes.HasFlag(ApiScopes.IdentityApiFullAccess)) { list.Add(IdentityApiFullAccess); } else if (apiScopes.HasFlag(ApiScopes.IdentityApiReadOnly)) { list.Add(IdentityApiReadOnly); } if (apiScopes.HasFlag(ApiScopes.JobApiFullAccess)) { list.Add(JobApiFullAccess); } else if (apiScopes.HasFlag(ApiScopes.JobApiReadOnly)) { list.Add(JobApiReadOnly); } return(String.Join(" ", list.ToArray())); }
private static List <string> GetDefaultScopes(DefaultScopes scopes) { var list = new List <string>(); if (scopes.HasFlag(DefaultScopes.OpenId)) { list.Add(Scopes.OpenId); } if (scopes.HasFlag(DefaultScopes.Profile)) { list.Add(Scopes.Profile); } if (scopes.HasFlag(DefaultScopes.Email)) { list.Add(Scopes.Email); } if (scopes.HasFlag(DefaultScopes.Role)) { list.Add(Scopes.Role); } if (scopes.HasFlag(DefaultScopes.OfflineAccess)) { list.Add(Scopes.OfflineAccess); } return(list); }
/// <summary> /// Constructs a new instance for a given service. /// </summary> /// <param name="serviceDescriptor">The protobuf descriptor for the service.</param> /// <param name="defaultEndpoint">The default endpoint to connect to.</param> /// <param name="defaultScopes">The default scopes for the service. Must not be null, and must not contain any null elements. May be empty.</param> /// <param name="supportsScopedJwts">Whether the service supports scoped JWTs as credentials.</param> /// <param name="transports">The transports supported by this service.</param> /// <param name="apiMetadata">The metadata for this API, including all of the services expected to be available at the same endpoint, and all associated protos.</param> public ServiceMetadata(ServiceDescriptor serviceDescriptor, string defaultEndpoint, IEnumerable <string> defaultScopes, bool supportsScopedJwts, ApiTransports transports, ApiMetadata apiMetadata) { ServiceDescriptor = GaxPreconditions.CheckNotNull(serviceDescriptor, nameof(serviceDescriptor)); Name = serviceDescriptor.Name; GaxPreconditions.CheckArgument(Name.Length > 0, nameof(serviceDescriptor), "Service has an empty name"); DefaultEndpoint = defaultEndpoint; DefaultScopes = GaxPreconditions.CheckNotNull(defaultScopes, nameof(defaultScopes)).ToList().AsReadOnly(); GaxPreconditions.CheckArgument(!DefaultScopes.Any(x => x == null), nameof(defaultScopes), "Scopes must not contain any null references"); SupportsScopedJwts = supportsScopedJwts; Transports = transports; ApiMetadata = GaxPreconditions.CheckNotNull(apiMetadata, nameof(apiMetadata)); }