Here is how I solved it:
I got it working finally. Below is code.
Download code from here for Chapter 12: http://prologika.com/power-bi-embedded-dashboards-without-authentication-ui/
Use below code to encrypt password:-
var secureString = new System.Security.SecureString();var password = "pwd here";var charArray = password.ToCharArray();foreach (var chara in charArray) { secureString.AppendChar(chara); }string myPassword = Util.EncryptString(secureString);Use below code, modification in above code to point to Common login path instead of TenantId based path.
// perform two-leg OAuth System.Net.WebRequest request = System.Net.WebRequest.Create("https://login.microsoftonline.com/common/oauth2/token") as System.Net.HttpWebRequest;