I am working on a C# asp.net web application using Google Cloud Platform. I am using the Secret Manager feature where I am storing my Google ClientSecret and ClientId. Then, I am using the code below, which I know for sure that works since my lecturer used it, to obtain the client secret and id using the secret manager feature, using my Google cloud project name, my secretId and version as parameters.
public string GetGoogleClientId(string projectId, string SecretId, string version)
{
SecretManagerServiceClient client = SecretManagerServiceClient.Create();
SecretVersionName secretVersionName = new SecretVersionName(projectId, SecretId, version);
AccessSecretVersionResponse result = client.AccessSecretVersion(secretVersionName);
string payload = result.Payload.Data.ToStringUtf8().ToString();
dynamic keys = JsonConvert.DeserializeObject(payload); //Gives the error here
JObject jObject = JObject.Parse(payload);
JToken jKey = jObject["Authentication:Google:ClientId"];
return jKey.ToString();
}
However, I am getting the following error:
'Unexpected character encountered while parsing value: . Path '', line 0, position 0.'
The generated string in variable payload returns the following string that I am trying to serialize:
{
"Authentication:Google:ClientSecret": "Hidden for security reasons",
"Authentication:Google:ClientId": "Hidden for security reasons"
}
What am I doing wrong please?