public static CreateAuthRequestResult CreateAuthRequest(Scope scope, string appName, string machineCode, int tokenId, int expires) { var authToken = new byte[30]; #if NET35 var rnd = RandomNumberGenerator.Create(); rnd.GetBytes(authToken); #else using (RandomNumberGenerator rnd = RandomNumberGenerator.Create()) { rnd.GetBytes(authToken); } #endif RSAParameters RSAParamsPrivate; string RSAParamsPublic = ""; #if NET40 || NET46 || NET35 || NET45 var rsa = new RSACryptoServiceProvider(2048); #else var rsa = RSA.Create(); rsa.KeySize = 2048; #endif RSAParamsPrivate = rsa.ExportParameters(true); RSAParamsPublic = JsonConvert.SerializeObject(rsa.ExportParameters(false)); var model = new AuthorizeAppModel() { AuthorizationToken = Convert.ToBase64String(authToken), Expires = expires, PublicKey = RSAParamsPublic, Scope = JsonConvert.SerializeObject(scope), VendorAppName = appName, DeviceName = Environment.GetEnvironmentVariable("COMPUTERNAME") ?? Environment.GetEnvironmentVariable("HOSTNAME"), //Environment.MachineName in .NET Standard > 1.5, MachineCode = machineCode, TokenId = tokenId, Algorithm = SignatureAlgorithm.RSA_2048 }; OpenBrowser(HelperMethods.DOMAIN + "User/AuthorizeApp/?" + GetQueryString(model)); return(new CreateAuthRequestResult { AuthorizationToken = authToken, Parameters = RSAParamsPrivate }); }
public static (byte[] authorizationToken, RSAParameters parameters) CreateAuthRequest(Scope scope, string appName, string machineCode, int tokenId, int expires, RSA rsa = null) { var authToken = new byte[30]; using (RandomNumberGenerator rnd = RandomNumberGenerator.Create()) { rnd.GetBytes(authToken); } RSAParameters RSAParamsPrivate; string RSAParamsPublic = ""; if (rsa == null) { // we are not targeting the .NET Framework. rsa = RSA.Create(); rsa.KeySize = 2048; } RSAParamsPrivate = rsa.ExportParameters(true); RSAParamsPublic = JsonConvert.SerializeObject(rsa.ExportParameters(false)); var model = new AuthorizeAppModel() { AuthorizationToken = Convert.ToBase64String(authToken), Expires = expires, PublicKey = RSAParamsPublic, Scope = JsonConvert.SerializeObject(scope), VendorAppName = appName, DeviceName = Environment.GetEnvironmentVariable("COMPUTERNAME") ?? Environment.GetEnvironmentVariable("HOSTNAME"), //Environment.MachineName in .NET Standard > 1.5, MachineCode = machineCode, TokenId = tokenId, Algorithm = SignatureAlgorithm.RSA_2048 }; OpenBrowser(HelperMethods.SERVER + "/User/AuthorizeApp/?" + GetQueryString(model)); return(authToken, RSAParamsPrivate); }