Xamarin Forms - Close view after successful login with Azure AD - azure

I'm successfully logging in my Xamarin Forms application with Azure AD.
The problem is that when I'm logged in through the webview opened by default with :
user = await AuthenticationManager.DefaultManager.CurrentClient.LoginAsync(MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory, true);
The created webview shows a message telling me that I'm logged in but I don't know how to close this view after that.
Is there an event I can use or am I doing something wrong and the webview is supposed to close itself upon complete authentication ?
EDIT :
I changed my call to :
user = await AuthenticationManager.DefaultManager.CurrentClient.LoginAsync(MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory, false);
Becase I didn't give an SID being a Xamarin Forms project.
The result is that the window closes now but I get and InvalidOperationException with the message :
Invalid format of the authentication response.
Any idea about the format I should give ? I don't see what I could change to be able to get the user connected.

Just leave off the true/false on the end.
For more information on authentication, see chapter 2 of http://aka.ms/zumobook

Related

Global exception page is not being rendered for ADB2C for exceptions instead the login page is rendered. Find a way to render custom error page

I am using azureadb2c integration. On the customised login page which is using a third party login just like google or fb after successfully entering user and password we have a consent page. When user accept the consent it redirects to our Home page but when the user clicks on not give consent by default it is taking the user to login page. What I want to do is instead of taking the user to the login page I want it to be redirected to a custom error page. I have gone through various answers here for handling this using an additional orchestration step but none worked.
Last I found that api.error should handle all unhandled exception but I dont know why it is being ignored and the login screen is shown.
This is the exception that I found in Application Insight:
"Exception": {
"Kind": "Handled",
"HResult": "80131500",
"Message": "An invalid response was received : 'Error: access_denied,Error Description: ConsentNotGiven'",
"Data": {
"IsPolicySpecificError": false
}
This is my api.error Content Definition, I tried replacing the LoadUri and tested it in Network in Google Debug Console but I cant see even that particular url getting hit.
<ContentDefinition Id="api.error">
<LoadUri>~/tenant/templates/AzureBlue/exception.cshtml</LoadUri>
<RecoveryUri>~/common/default_page_error.html</RecoveryUri>
<DataUri>urn:com:microsoft:aad:b2c:elements:contract:globalexception:1.2.1</DataUri>
<Metadata>
<Item Key="DisplayName">Error page</Item>
</Metadata>
</ContentDefinition>
It will be helpful if someone can show how I can get this page rendered on every exception. Thanks
The way I do this is to use a paragraph.
I tried multiple solution to get the api.error page working but I wasn't able to accomplish the task. My major aim was to render the custom error page whenever user clicks the cancel or not giving accent button which was throwing an exception with above code : AADB2C90273
Finally I have got the solution and it was to edit the Startup file and to fetch the event that gets triggered when the exception is raised in ADB2C.
The project being in .Net Core 3.1 it was quite difficult to get the way to set up OpenIdConnectOptions with AzureADB2c events as we weren't able to find any document related to it.
I added below code in the Startup.cs file in the ConfigureServices method :
services.Configure<OpenIdConnectOptions>(Configuration.GetSection("AzureAdB2C"))
.Configure<OpenIdConnectOptions>(OpenIdConnectDefaults.AuthenticationScheme, options =>
{
options.Events.OnMessageReceived = (context) =>
{
if (!string.IsNullOrEmpty(context.ProtocolMessage.Error) &&
!string.IsNullOrEmpty(context.ProtocolMessage.ErrorDescription) &&
context.ProtocolMessage.ErrorDescription.StartsWith("AADB2C90273"))
{
context.Response.Redirect("/Home/Error");
context.HandleResponse();
}
return Task.CompletedTask;
};
});
where Configuration.GetSection("AzureAdB2C") is used to get the properties defined in json file and OnMessageReceived was the event that was getting triggered when adb2c was having an exception. I redirected it to the custom error page that I created.
I hope this helps someone.

How to do user authentication using a mysql databse

On a website:
After a successful login, how to stop sending the user to localhost/login cause he's already logged in, but send him instead to a localhost/index where there's a logout button.
Video reference (min 00:48)
https://youtu.be/DcB1Ge0HQ4I
That's a simple task ,,,did you create $_SESSION['loggedin'] = true;

Google API SignIn HostedDomain cleanup problem

We implement the Sign-In on iOS using the Google API in our project. Customers must have a possibility to select the HostedDomain to limit the allowed account pull to the single domain.
SignIn.SharedInstance.HostedDomain = "domainName.com";
works perfectly.
The problem is when we want to Logout the user and log in it back with unrestricted HostedDomain
SignIn.SharedInstance.HostedDomain == null; // <-Default Value
When I try to set it to
SignIn.SharedInstance.HostedDomain=string.empty;
I filter everything.
When I try to set it to null
SignIn.SharedInstance.HostedDomain=null;
I get the exception.
Calling:
SignIn.SharedInstance.Dispose();
doesn't help.
The question is: How is possible to reset the HostedDomain filtering to the initial stage - allow everything without of the app restart.
Our implementation based on Xamarin iOS native, but we see the same problem in Swift or Objective-C.
The wrapper for the Gooogle SDK we use:
Xamarin.Google.iOS.SignIn

Open navigation properties are not supported on OpenTypes. Property name: 'DirectoryDataService.changePassword'

Error shown When i try to update user password using Microsoft.Azure.ActiveDirectory.GraphClient
user.ChangePasswordAsync(currentPassword, newPassword);
It works correctly for me with following code.
await activeDirectoryClient.Users["userObjectId"].ChangePasswordAsync("oldPassword", "newPassword");
or
var user = activeDirectoryClient.Users.GetByObjectId("userObjectId")
await user.ChangePasswordAsync("oldPassword", "newPassword");
But I can this reproduce the error information with following code.
var user =(User)activeDirectoryClient.Users.GetByObjectId("userObjectId").ExecuteAsync().Result;
await user.ChangePasswordAsync("oldPassword", "newPassword");
I capture the request with fiddler then I find that 400 error. And the request url is
https://graph.windows.net/{tenantId}/directoryObjects/{userId}/changePassword?api-version=1.6
But the change password Graph API is
https://graph.windows.net/{tenantId}/users/<objectId>/changePassword or /users/userPrincipalName/changePassword
I assume that it is the reason why get that error information.
Note: Call the changePassword action for the signed-in user to change their own password.
We also could use the Microsoft graph SDK to do that. For more information, please refer to another SO thread.

When I do document preview it will logout first time?

I have liferay open office integration. My problem is when I preview any document after login first time it is logout and ask to login again. Next time it is working fine the problem persist while document preview generation and after user log first time. suppose there are 5 page of document only 2 page display other while show processing image.
Below are logs come while logout.
06:55:17,743 ERROR [ajp-bio-8009-exec-88][PollerServlet:63] No channel exists with user id 1810503
06:55:17,782 ERROR [ajp-bio-8009-exec-88][status_jsp:752] No channel exists with user id 1810503
06:55:26,360 ERROR [ajp-bio-8009-exec-95][PollerServlet:63] No channel exists with user id 1810503
06:55:26,403 ERROR [ajp-bio-8009-exec-95][status_jsp:752] No channel exists with user id 1810503
Above logs come each time when i log in.
I am using Liferay 6.2 CE GA3 + Mysql + Openoffice + xuggler.
I have seen liferay issues related with No channel exists with user id but it does not answer my question

Resources