private void TryLogin_Refresh() { /* SNIPPET 1: START */ // Automatically refresh token using plain credentials client.TryLogin("username", "password"); // Do not automatically refresh token using plain credentials client.TryLogin("username", "password", false); /* SNIPPET 1: END */ /* SNIPPET 2: START */ // Read target from Credential Manager and automatically refresh token client.TryLogin("metasys-energy-app"); // Read target from Credential Manager and do not refresh token client.TryLogin("metasys-energy-app", false); /* SNIPPET 2: END */ /* SNIPPET 3: START */ AccessToken accessToken = client.TryLogin("metasys-energy-app"); Console.WriteLine(accessToken); /* * { * "Issuer": "metasysserver", * "IssuedTo": "metasysapiuser", * "Token": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IkJzR0lWelVZcjN0MkI0RGRtT1ljMTdBLVZJOCIsImtpZCI6IkJzR0lWelVZcjN0MkI0RGRtT1ljMTdBLVZJOCJ9.eyJpc3MiOiJodHRwOi8vbG9jYWxob3N0Ojk1MDYvQVBJLkF1dGhlbnRpY2F0aW9uU2VydmljZSIsImF1ZCI6Imh0dHA6Ly9sb2NhbGhvc3Q6OTUwNi9BUEkuQXV0aGVudGljYXRpb25TZXJ2aWNlL3Jlc291cmNlcyIsImV4cCI6MTU4OTI5MzEzMCwibmJmIjoxNTg5MjkxMzMwLCJjbGllbnRfaWQiOiJtZXRhc3lzX3VpIiwic2NvcGUiOlsibWV0YXN5c19hcGkiLCJvZmZsaW5lX2FjY2VzcyIsIm9wZW5pZCJdLCJzdWIiOiI4ZGE4YjE4Yy1lMTk1LTRlMmMtOGU2Zi0zNTE2Zjc0ZWFhNGIiLCJhdXRoX3RpbWUiOjE1ODkyOTEzMzAsImlkcCI6Imlkc3J2IiwiVXNlcklkIjoiMSIsIlVzZXJOYW1lIjoibWV0YXN5c3N5c2FnZW50IiwiSXNBZG1pbiI6IlRydWUiLCJJc1Bhc3N3b3JkQ2hhbmdlUmVxdWlyZWQiOiJGYWxzZSIsIklzVGVybXNBbmRDb25kaXRpb25zUmVxdWlyZWQiOiJGYWxzZSIsIkxpY2Vuc2VJbmZvIjoie1wiSXNMaWNlbnNlZFwiOnRydWUsXCJMaWNlbnNlVHlwZVwiOlwiZ3JhY2VcIn0iLCJDdWx0dXJlIjoiZW4tVVMiLCJhbXIiOlsicGFzc3dvcmQiXX0.egzw1bs1831pEBWWXbBOYWGU5wFsI3sEnL7RgCIHHbHmcxtpPPqLq54znpoUoLFrMUeymZj5rkrt_mF-CNIpCE3halZNAH-CR1U46LTZi5CMaDfYlP-wHxikAGV5GwFjlHjGNOUaFtd7n4yC5sH08pHQfXXD5gKDm_FVMfUJXAo-E8gmrkU0wMn5U2FRyQyj7Yhq6jaj7MPTF__Xz46sG3WtDr45WK2NmuwiLDv408URZ5fJxlMngRpjSIONHVAIwna_H0AguHiIELkvuRVYcRqIH5kb1YdFt-3fsnTV9xwpozZZ44dh-4I7x466I-UGlLHAnScWILUbPcpRNWm0Uw", * "Expires": "2020-05-12T14:18:51Z" * } */ /* SNIPPET 3: END */ /* SNIPPET 4: START */ client.Refresh(); /* SNIPPET 4: END */ }
public void Run() { try { Console.WriteLine("\nRefreshing Token..."); var token = client.Refresh(); Console.WriteLine($"Access token: {token.Token} expires {token.Expires}."); } catch (Exception exception) { log.Logger.Error(string.Format("An error occured while getting refresh token information - {0}", exception.Message)); Console.WriteLine("\n \nAn Error occurred. Press Enter to return to Main Menu"); } Console.ReadLine(); }