How to use VGIdentityServer without VGRuntime in .Net ?

Estimated reading: 1 minute 68 views

Requirement

You need to have:

  • VGIdentityServer running
  • In your VGApplication, a VGIdentityServer Client configuration

How to call VGIdentityServer ?

You need to call VGIdentityServer to get the AccessToken

var client = new HttpClient();

string VGAccessToken = String.Empty;//Add option for the cache
if (string.IsNullOrEmpty(accessToken))
{
	var response1 = client.RequestPasswordTokenAsync(new PasswordTokenRequest
	{
		Address = "<VGIdentityServerUrl>", 
		ClientId = clientId,
		ClientSecret = "secret",
		Scope = "openid profile VGActivityDate VGApplications VGIsApproved VGIsLocked VGPermissions VGProfile VGRoles VGToken IdentityServerApi",
		UserName = Username,
		Password = Password,
		Parameters =
		{
			{ "AuthenticationMethod", "VisualGuard"}
		}
	}).Result;
	VGAccessToken = response1?.AccessToken;
}


How to call your Web API BackOffice ?

You can call your Web API BackOffice secure by Visual-Guard ?

var client = new HttpClient();
client.SetBearerToken("<VGAccessToken>");
string url = "http://<WebAPIUrl>/Calculator/Add?a=5&b=10";// Call to WebAPI
var content = client.GetStringAsync(url).Result;
Answer = content;