Enabling Single Sign On in TEdgeBrowser - delphi

I have some C# code that shows how to enable Single Sign On in WebView2.
The TEdgeBrowser doesn't expose any of the properties that the C# code uses. In particular the interface defined in the Winapi.WebView2 unit for ICoreWebView2EnvironmentOptions doesn't have the functions for getting or setting AllowSingleSignOnUsingOSPrimaryAccount defined in it. I believe that this is because it was created from WebView2.tlb on 07/05/2020 whereas the property was added in the version released September 10, 2020.
What options do I have? Do I need to create my own version of WebView2 from the latest tlb and then duplicate the code in the Vcl.Edge unit to get a component with the SSO option enabled?
I don't need a visual component - I'd be happy to create the browser in code.
The C# code is:
private async void Form1_Load(object sender, EventArgs e)
{
var browser = new WebView2();
var options = new CoreWebView2EnvironmentOptions();
options.AllowSingleSignOnUsingOSPrimaryAccount = true;
var environment = await CoreWebView2Environment.CreateAsync(options: options).ConfigureAwait(false);
await browser.EnsureCoreWebView2Async(environment).ConfigureAwait(false);
Invoke((MethodInvoker)(() =>
{
browser.Dock = DockStyle.Fill;
this.Controls.Add(browser);
browser.Source = new Uri(https://example.com);
}));
}

Try WebView4Delphi instead. WebView4Delphi is fully updated to the latest WebView2 version and it supports all the WebView2 interfaces.
You only have to add this line before the GlobalWebView2Loader.StartWebView2 call :
GlobalWebView2Loader.AllowSingleSignOnUsingOSPrimaryAccount := True;
The demos use the initialization section of the main unit to create GlobalWebView2Loader and set the properties. If you use the SimpleBrowser demo as a template for your application then you would have to add the previous line here.
That property in GlobalWebView2Loader is used for all the browsers that share the same ICoreWebView2Environment which is the default behavior.
In case you need to create a browser with an independent ICoreWebView2Environment then you have to set this property before the TWVBrowserBase.CreateBrowser call :
MyWVBrowser.AllowSingleSignOnUsingOSPrimaryAccount := True;
MyWVBrowser would be an instance of TWVBrowser.

Related

Using DataConnectionDialog

When I am attempting to use the DataConnectionDialog from NuGet (version 1.2), I receive the Advanced Settings dialog for setting up the Database Connection. Is there some Setting I have missed or additional library to retreive?
Code:
using System;
using Microsoft.Data.ConnectionUI;
DataConnectionDialog dcd = new DataConnectionDialog();
DataSource.AddStandardDataSources(dcd);
dcd.SelectedDataSource = DataSource.SqlDataSource;
dcd.SelectedDataProvider = DataProvider.SqlDataProvider;
DataConnectionDialog.Show(dcd);
Output:
What I want (this comes from the datasource wizard in Visual Studio Community 2015):
I happened to stumble on the same issue. From my main form, I called an async method using Task.Factory.StartNew. This method tries to open the Data Connection Dialog but it would show the Advance Settings dialog box instead.
During troubleshooting, I replaced the DataConnectionDialog with a OpenFileDialog and this gave me a ThreadStateException which pointed me towards the solution.
To solve it, I had to put the code in a separate function, e.g. AskConnectionString and call it using Control.Invoke.
e.g.
public void btnConnString_Click(object sender, EventArgs e)
{
_connectionString = (string)this.Invoke(AskConnectionString);
}
public string AskConnectionString()
{
DataConnectionDialog dcd = new DataConnectionDialog();
DataSource.AddStandardDataSources(dcd);
dcd.SelectedDataSource = DataSource.SqlDataSource;
dcd.SelectedDataProvider = DataProvider.SqlDataProvider;
DataConnectionDialog.Show(dcd);
return dcd.ConnectionString;
}

How can I implement a custom challenge handler in Xamarin for iOS using IBM MobileFirst?

I'm trying to implement an adapter-based authentication using IBM MobileFirst Platform Foundation 6.3 and Xamarin in iOS.
I have followed the IBM documentation on how to setup a customSecurityTest, adding realms and equivalent loginModules within authenticationConfig.xml. I have then setup 2 adapter procedures:
authenticateUser with securityTest="wl_unprotected", and another
HelloFromServer with a securityTest="SingleStepAuthAdapter" that actually does a user authentication, and executing WL.Server.setActiveUser("SingleStepAuthRealm", userIdentity) to create the user identity.
I have then created an iOS app using Xamarin Studio. Tried to invoke HelloFromServer, which as expected runs my ChallengeHandler module BUT within the HandleChallenge method while trying to invoke the authenticateUser procedure on the server, it respond back with another authRequired=TRUE.
Anybody having the same problem?
You did not provide any useful implementation code that can be inspected for errors - add both the adapter authentication implementation as well as the client-side code of the challenge handler.
While I have no experience with Xamarin, it should be noted that in order to get started you could:
Use the same exact implementation as done in the Adapter-based authentication tutorial. That is, the implementation in the adapter files, project configuration and so on.
Follow through the native iOS implementation, also based on the tutorial
The MFP Studio project and the native iOS project can be downloaded from here.
If you are repeatedly getting back authRequired=true, it looks like you are not notifying the server of the success from your HandleChallenge function. You can refer to the CustomChallengeHandler.cs provided with the sample that is shipped with the component. This is coded to handle a form-based challenge. You can modify it to handle an realm for adapter-based authentication.
So, here are the changes you need to do
1) You should implement the GetAdapterAuthenticationParameters method in your ChallengeHandler class.
For example,
public AdapterAuthenticationInfo AdapterAuthenticationParameters = new AdapterAuthenticationInfo();
....
public override AdapterAuthenticationInfo GetAdapterAuthenticationParameters ()
{
return AdapterAuthenticationParameters;
}
2) In the HandleChallenge function of your ChallengeHandler class, set the isAuthRequired = true. For example,
if (challenge.ResponseJSON["authRequired"] == true)
{
WorklightProcedureInvocationData invocationData = new WorklightProcedureInvocationData("DemoAdapter",
"submitAuthentication" , new object[1]); // Add the parameters you want to pass to the adapter
AdapterAuthenticationParameters.InvocationData = invocationData;
AdapterAuthenticationParameters.RequestOptions = null;
isAdapterAuth = true;
}
else
{
isAdapterAuth = false;
authSuccess = true;
}

Inject bridge-code in JavaFX WebView before page-load?

I want to load some content or page in a JavaFX WebView and offer a Bridge object to Java so the content of the page can do calls into java.
The basic concept of how to do this is described here: https://blogs.oracle.com/javafx/entry/communicating_between_javascript_and_javafx
Now my question is: When is a good time inject the bridge-object into the WebView so it is available as soon as possible.
One option would be after page load as described here: https://stackoverflow.com/a/17612361/1520422
But is there a way to inject this sooner (before the page content itself is initialized), so the bridge-object is available DURING page-load (and not only after page-load)?
Since no one has answered, I'll tell you how I'm doing it, although it is ugly. This provides the ability for the page to function normally in non-Java environments but receive a Java object in Java environments.
I start by providing an onStatusChanged handler to the WebEngine. It listens for a magic value for window.status. If the magic value is received, the handler installs the Java object. (In my case, it's more complex, because I have some more complex orchestration: I'm executing a script that provides a client-side API for the page and then sets another magic value on window.status to cause the Java object to be sent to an initialization method of the client-side API).
Then in my target page, I have the following code in the first script in the page:
window.status = "MY-MAGIC-VALUE";
window.status = "";
This code is essentially a no-op in a "normal" browser but triggers the initialization when running in the custom JavaFX embedding.
In Java 8, you can trigger event changing from SCHEDULED to RUNNING to inject objects at this time. The objects will present in WebEngine before JavaScript running. Java 7, I see the state machine quite differs in operating, no solution given for Java 7.
webEngine.getLoadWorker().stateProperty().addListener(
new ChangeListener<State>(){
public void changed(ObservableValue<? extends State> ov,
State oldState,
State newState)
{
// System.out.println("old: "+oldState+", new: "+newState);
if(newState == State.RUNNING &&
oldState == State.SCHEDULED){
JSObject window = (JSObject)webEngine.executeScript("window");
window.setMember("foutput", foutput);
}
}
});

ImageResizer and image files without an extension

I've been using ImageResizer.net just fine in our web app, but now I need it to resize and serve images that don't (and cannot) have a file extension, like this one:
http://localhost:58306/ClientImages/Batch/2012/12/10/f45198b7c452466684a4079de8d5f85f?width=600
In this situation, I know that my files are always TIFF's, but they wont have a file extension.
What are my options?
/resizer.debug.ashx: https://gist.github.com/raw/9c867823c983f0e5be10/4db31cb21af8b9b36f0aa4e765f6f459ba4b309f/gistfile1.txt
Update
I followed Computer Linguist's instructions:
protected void Application_Start()
{
Config.Current.Pipeline.PostAuthorizeRequestStart +=
delegate
{
var path = Config.Current.Pipeline.PreRewritePath;
var clientImgsRelPath = PathUtils.ResolveAppRelative("~/ClientImages/");
var isClientImageRequest = path.StartsWith(clientImgsRelPath, StringComparison.OrdinalIgnoreCase);
if (isClientImageRequest)
Config.Current.Pipeline.SkipFileTypeCheck = true;
};
// other app start code here
}
http://localhost:58306/ClientImages/Batch/2012/12/10/92d67b45584144beb5f791aaaf760252?width=600 just responds with the original image with no resizing.
This was also asked about here: http://imageresizing.net/docs/howto/cache-non-images#comment-571615564
This is happening during development with the Cassini or Visual Studio web server or whatever you want to call it.
First, you MUST be using IIS7 Integrated mode. Classic mode will not work; it does not permit ASP.NET access to extensionless requests
ImageResizer can't know that extension-less URLs are images unless you explicitly tell it.
This doc explains:
http://imageresizing.net/docs/howto/cache-non-images
Essentially, you'll end up performing logic (usually String.StartsWith) on your URLs to find out if ImageResizer should treat the file as an image.
Config.Current.Pipeline.PostAuthorizeRequestStart += delegate(IHttpModule sender, HttpContext context) {
string path = Config.Current.Pipeline.PreRewritePath;
//Skip the file extension check for everything in this folder:
if (path.StartsWith(PathUtils.ResolveAppRelative("~/folder/of/images"),
StringComparison.OrdinalIgnoreCase)){
Config.Current.Pipeline.SkipFileTypeCheck = true;
}
};
You should register this event handler in Application_Start in global.asax.

What do I need to know to create a source code editor?

Say I want to create a source code editor for ocaml programming language, where do I start? I am looking to create an editor for the Windows platform as a hobby project. My primary skill is in web development. I have developed windows apps long time ago. I have no clue how it is done with todays available tools. I have visual studio 2008 and C# is my language of choice.
You need to know:
OCAML Syntax, Features, Keywords, Functions etc...
C# as this is your native language I guess
You need to know what features you wanna implement
...if it's using a GUI or just from a terminal like nano/vim
how syntax highlighting works
how to open and save files
how autocompletion works
etc..
You might want to take look at some open source editors like dev-c++ or gedit
Also, as you in person are more web-devvy, you might want to start creating one which runs in a web browser. This is often easier and helps you understand the basics of creating a code editor. Later you can always write one for desktops.
If you are most comfortable in Visual Studio, then you can use the Visual Studio Shell to create your own IDE based on that foundation.
Here is a podcast that gives a good overview:
http://www.code-magazine.com/codecast/index.aspx?messageid=32b9401a-140d-4acb-95bb-6accd3a3dafc
Also, as a reference, the IronPython Studio was created using the Visual Studio 2008 Shell:
http://ironpythonstudio.codeplex.com/
Browsing that source code should give you a good starting point.
a lighter-weight alternative is to use the RichEdit control
example:
http://www.codeproject.com/Messages/3401956/NET-Richedit-Control.aspx
// http://www.codeproject.com/Messages/3401956/NET-Richedit-Control.aspx
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace RichEditor
{
public class RichTextBoxEx : RichTextBox
{
IntPtr mHandle = IntPtr.Zero;
protected override CreateParams CreateParams
{
get
{
// Prevent module being loaded multiple times.
if (this.mHandle == IntPtr.Zero)
{
// load the library to obtain an instance of the RichEdit50 class.
this.mHandle = LoadLibrary("msftedit.dll");
}
// If module loaded, reset ClassName.
if (this.mHandle != IntPtr.Zero)
{
CreateParams cParams = base.CreateParams;
// Check Unicode or ANSI system and set appropriate ClassName.
if (Marshal.SystemDefaultCharSize == 1)
{
cParams.ClassName = "RichEdit50A";
}
else
{
cParams.ClassName = "RichEdit50W";
}
return cParams;
}
else // Module wasnt loaded, return default .NET RichEdit20 CreateParams.
{
return base.CreateParams;
}
}
}
~RichTextBoxEx()
{
//Free loaded Library.
if (mHandle != IntPtr.Zero)
{
FreeLibrary(mHandle);
}
}
[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr LoadLibrary(String lpFileName);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool FreeLibrary(IntPtr hModule);
}
}
You could use Scintilla. It has syntax highlighting and some other features. Also, it has a .NET Version available here.
Another good tool is Alsing Syntax Box:
Powerful Syntax Highlight Windows
Forms Control for the Microsoft.NET
Platform. Written in 100% managed C#.
Supports syntax highlighting and code
folding for just about any programming
language.
With Alsing Syntax Box, you can define a syntax file (just like this one for C#) and later have a intellisense like feature.
You can start with one of them for your editor.

Resources