static void Main(string[] args) { InitConfig(); HybridFlow.OcsUrl = GetConfigValue("OCSUrl"); HybridFlow.RedirectHost = GetConfigValue("HybridFlow:RedirectHost"); HybridFlow.RedirectPort = Parse(GetConfigValue("HybridFlow:RedirectPort")); HybridFlow.RedirectPath = GetConfigValue("HybridFlow:RedirectPath"); var tenantId = GetConfigValue("TenantId"); var clientId = GetConfigValue("HybridFlow:ClientId"); var clientSecret = GetConfigValue("HybridFlow:ClientSecret"); var scope = GetConfigValue("HybridFlow:Scope"); // Get access token and refresh token. var(accessToken, refreshToken, expiration) = HybridFlow.GetHybridFlowAccessToken(clientId, clientSecret, scope, tenantId); Console.WriteLine("Access Token: " + accessToken); var refreshStatus = !string.IsNullOrEmpty(refreshToken) ? refreshToken : "No refresh token requested"; Console.WriteLine("Refresh Token: " + refreshStatus); Console.WriteLine("Expires: " + expiration); // Make a request to GetTenant endpoint Console.WriteLine(GetRequest($"{GetConfigValue("OCSUrl")}/api/Tenants/{tenantId}", accessToken).Result ? "Request succeeded" : "request failed"); // Check if offline_access scope has been requested. This scope can be requested for hybrid clients // that have been created with AllowRefreshToken option set to true, which is also the default option. if (scope.Contains("offline_access")) { // Get a new access token from a refresh token. If the previous access token has not expired it can still be used. // This will also reissue a new refresh token. Old refresh token will no longer be valid after use. (accessToken, refreshToken, expiration) = HybridFlow.GetAccessTokenFromRefreshToken(refreshToken, clientId, clientSecret); Console.WriteLine("Access Token: " + accessToken); Console.WriteLine("Refresh Token: " + refreshToken); Console.WriteLine("Expires: " + expiration); } else { Console.WriteLine("No refresh token requested."); } // Make a request to GetTenant endpoint Console.WriteLine(GetRequest($"{GetConfigValue("OCSUrl")}/api/Tenants/{tenantId}", accessToken).Result ? "Request succeeded" : "request failed"); }
public static void Main(string[] args) { InitConfig(); HybridFlow.OcsUrl = GetConfigValue("Resource"); HybridFlow.RedirectHost = GetConfigValue("RedirectHost"); HybridFlow.RedirectPort = Parse(GetConfigValue("RedirectPort")); HybridFlow.RedirectPath = GetConfigValue("RedirectPath"); var tenantId = GetConfigValue("TenantId"); var clientId = GetConfigValue("ClientId"); var clientSecret = GetConfigValue("ClientKey"); var scope = GetConfigValue("Scope"); // Get access token and refresh token. var(accessToken, refreshToken, expiration) = HybridFlow.GetHybridFlowAccessToken(clientId, clientSecret, scope, tenantId); Console.WriteLine("Access Token: " + accessToken); Console.WriteLine("Refresh Token: " + refreshToken); Console.WriteLine("Expires: " + expiration); // Make a request to GetTenant endpoint Console.WriteLine(GetRequest($"{GetConfigValue("OCSUrl")}/api/Tenants/{tenantId}", accessToken).Result ? "Request succeeded" : "request failed"); // Get a new access token from a refresh token. If the previous access token has not expired it can still be used. // This will also reissue a new refresh token. Old refresh token will no longer be valid after use. (accessToken, refreshToken, expiration) = HybridFlow.GetAccessTokenFromRefreshToken(refreshToken, clientId, clientSecret); Console.WriteLine("Access Token: " + accessToken); Console.WriteLine("Refresh Token: " + refreshToken); Console.WriteLine("Expires: " + expiration); // Make a request to GetTenant endpoint Console.WriteLine(GetRequest($"{GetConfigValue("OCSUrl")}/api/Tenants/{tenantId}", accessToken).Result ? "Request succeeded" : "request failed"); }
public static void Main(string[] args) { bool test = false; try { InitConfig(); if (SystemBrowser.openBrowser == null) { SystemBrowser.openBrowser = new OpenSystemBrowser(); } else { test = true; SystemBrowser.password = GetConfigValue("Password"); SystemBrowser.userName = GetConfigValue("UserName"); } HybridFlow.OcsUrl = GetConfigValue("Resource"); HybridFlow.RedirectHost = GetConfigValue("RedirectHost"); HybridFlow.RedirectPort = Parse(GetConfigValue("RedirectPort")); HybridFlow.RedirectPath = GetConfigValue("RedirectPath"); var tenantId = GetConfigValue("TenantId"); var clientId = GetConfigValue("ClientId"); var clientSecret = GetConfigValue("ClientKey"); var ocsUrl = GetConfigValue("Resource"); var apiVersion = GetConfigValue("ApiVersion"); // Get access token and refresh token. var(accessToken, refreshToken, expiration) = HybridFlow.GetHybridFlowAccessToken(clientId, clientSecret, tenantId); Console.WriteLine("Access Token: " + accessToken); Console.WriteLine("Refresh Token: " + refreshToken); Console.WriteLine("Expires: " + expiration); // Make a request to Get Users endpoint var result1 = GetRequest($"{ocsUrl}/api/{apiVersion}/Tenants/{tenantId}/Users", accessToken).Result; Console.WriteLine(result1 ? "Request succeeded" : "request failed"); if (!result1) { throw new Exception("Request failed"); } // Get a new access token from a refresh token. If the previous access token has not expired it can still be used. // This will also reissue a new refresh token. Old refresh token will no longer be valid after use. (accessToken, refreshToken, expiration) = HybridFlow.GetAccessTokenFromRefreshToken(refreshToken, clientId, clientSecret); Console.WriteLine("Access Token: " + accessToken); Console.WriteLine("Refresh Token: " + refreshToken); Console.WriteLine("Expires: " + expiration); // Make a request to Get Users endpoint var result2 = GetRequest($"{ocsUrl}/api/{apiVersion}/Tenants/{tenantId}/Users", accessToken).Result; Console.WriteLine(result2 ? "Request succeeded" : "request failed"); if (!result2) { throw new Exception("Request failed"); } } catch (Exception e) { Console.WriteLine(e.ToString()); if (test) { throw e; } } if (!test) { Console.ReadLine(); } }