/// <summary> /// Used to generate tokens or verify the validity of tokens /// </summary> /// <returns>Validation results</returns> public async Task <InitResultType> InitAsync() { InitResultType result = InitResultType.Success; if (string.IsNullOrEmpty(Token)) { var token = await NetworkTools.GetClientCredentialsToken(_clientId, _clientSecret, _permissions, (msg) => { var args = new ExceptionEventArgs(msg); OnException?.Invoke(this, args); }); if (token.IsError) { if (token.ErrorType == IdentityModel.Client.ResponseErrorType.Http) { result = InitResultType.HttpError; } else { result = InitResultType.InvalidParameters; } } else { Token = token.AccessToken; result = InitResultType.Success; } } else { string testRoute = "basic/earthStatus"; await NetworkTools.GetEntityAsync <EarthStatus>(testRoute, Token, (msg) => { if (msg.Code == 601) { result = InitResultType.HttpError; } else { result = InitResultType.TokenExpiry; } }); } return(result); }