Azure B2C with Laravel Socialite - php

I'm trying to integrate an azure b2c provider with laravel socialite.
I already add socialite and additional azure provider from socialiteproviders.com
I edited the Provider.php class to change the getAuthUrl schema in order to use tenant instead login.microsoftonline.com and it works fine:
The login page shown and redirected then to setup callback.
In the callback authorization code arrives but the socialite can't use it to obtain the idToken.. (I can calling explicity ../oauth2/v2.0/token but I think that socialite must to take care of it..)
And if I call
\Laravel\Socialite\Facades\Socialite::driver('azure')->setConfig($config)->stateless()->user()
I got error from microsoft graph
Or.. if I got manually the idToken and call \Laravel\Socialite\Facades\Socialite::driver('azure')->setConfig($config)->stateless()->userFromToken()
it is not recognized.
What's wrong in my flow? Any suggestions to integrate azure b2c in laravel with socialite?

Related

Azure Authentication Middleware for a Laravel App

First of all, i am very new to Laravel and Azure and i am not very sure what i am doing.
I want to add Authentication to my Laravel Web Application.
I followed the instructions in this Link to do that:
When i press my Login Button, which leeds me to "/login/azure" i get directed to
https://login.microsoftonline.com/ef7e48cb-7676-47e9-9a28-c69910d92560/oauth2/authorize?response_type=code&client_id=3a0621c0-2848-47f5-83ee-bebeede8aaa6&resource=
I can add my credentials here and then i get redirected to my welcome page and there is a very long code in my uri and after that a short session code. What does this mean? Am i logged in now? How can i test that and how can i create different roles for my Application now?
Could it be that i have to enable the default laravel Authentication with the "php artisan make:auth" command? Is it bad that i have no resource in the uri u see above? What do i have to put there?
First, understand OAuth on Azure.
https://learn.microsoft.com/en-us/azure/active-directory/develop/v1-protocols-oauth-code
You do not need a resource if you are using the "converged" endpoint (v2). The endpoint you show is v1, so yes, you need to specify what resource you're authenticating against and what granted permissions are for it. Check out What is the Resource parameter in Windows Azure AD tenant application oAuth 2.0 specification
Have you created an app registration (see the Azure Active Directory blade)?
Welcome to OAuth.

"Your request included an invalid SAML response" in integrating Azure AD and AWS

Followed the steps outlined in https://learn.microsoft.com/en-us/azure/active-directory/active-directory-saas-amazon-web-service-tutorial and as Dirk_Nelson points out in the comments:
Error: Your request included an invalid SAML response. To logout,
click here.
After digging around AWS' documentation, I found this article:
http://docs.aws.amazon.com/IAM/latest/UserGuide/troubleshoot_saml.html#troubleshoot_saml_invalid-response
Attribute Name rolesessionname changed to RoleSessionName
Attribute Name role changed to Role
Namespace needs to be https://aws.amazon.com/SAML/Attributes for BOTH RoleSessionName and Role
After making those changes in the Azure portal I was able to
successfully authenticate.
Though I already had this. Alternatively, the Amazon troubleshooting page says this is due to the Role lacking attribute values with the ARN.
<AttributeValue>arn:aws:iam::account-number:role/role-name1,arn:aws:iam::account-number:saml-provider/provider-name</AttributeValue>
I tried this as well, but no luck. Is there anything else that could be missing?
End goal is to login through Amazon Cognito with users stored in Azure AD, and this seems to be a solution unless I'm interpreting this as the opposite route of what I need.
To sum up the above discussion:
Invalid SAML response was due to missing attribute (Role) in SAML response
Use Case
Implement authentication in PHP application using Azure AD using a custom UI
Solutions explored
Integrate Azure AD with Cognito as a SAML IdP
Integrate Azure AD with Cognito as an OIDC Provider
Use Azure AD directly in your app as an OIDC provider
Skip AWS integration altogether & use custom libraries
Issue
All the above solutions redirect to Microsoft login page
Next steps
Skip AWS integration, for sure
Using default Azure login UI would have the simplest solution but not viable
Look for some PHP library which can be used to do the same. Most IdPs like Cognito, Auth0 tec. provide SDKs which can be used to get tokens pragmatically using Username & Password i.e. one can implement his own login UI & extract username, password & use it in the SDK methods. Check if it is possible with Azure SDKs
Possible solution with this library but untested and not in PHP.

How create one-point authorization?

There are two API. The first is responsible for the authentication user, the second for a local project. Local project does not create an account. How to enable the user to log in local project using the first API?
Maybe
On the client login window appears, enter the login password. Dispatched at the API project:
api.project.com/login .....
API project sends data to the authorization API
api.сompany.com / login .....
If everything is fine - it returns "OK", and then issues a token API project and the client has been working with it.
The goal to make a common account for all projects. But how to implement API - I do not understand
Thanks!

Add multiple domain Azure App via Code

Hi I have PHP CRM running in Azure server,my requirement is that user should be able to add there own custom domains(they will do the DNS configurations seperately) to app by themselves through CRM site,is there any REST API call to achieve that,i searched a lot but couldn't find any documents from Azure,
i did find these from stack
Programatically add domain name to azure website
Add a domain to an Azure web site via code
i tried above expample using Chrome Postman app
App(instanceName) name name is "example"
"https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups/{myResourceGroup}/providers/Microsoft.Web/sites/{instanceName}/config/web?api-version=2015-08-01"
used both POST and PUT method
{ "properties": { "HostNames":"example.com, crm.example.com" } }
i tried these methods but all i am getting a error "Authentication failed. The 'Authorization' header is not present or provided in an invalid format",i believe something wrong with json values,
example.com.au is my existing website and crm.example.com is my domain name i want to add,is it correct, am i missing anything,please help me
As all of the tasks that you do on resources using the Azure Resource Manager must be authenticated with Azure Active Directory. So To implement Azure Resource Manager Rest APIs, we need to follow the steps in authenticate Azure Recourse Manager requests first to set up authentication.
Generally:
Add an application to the Azure Active Directory tenant.
Set permissions for the application that you added.
Get the token for authenticating requests to Azure Resource Manager.
--Update--
To get the access token for Azure Resource Manager, we should follow the steps shows in Authorization Code Grant Flow:
1,Request an authorization code
The build-up URL will redirect to the sso page, after login we can get the code value which will be used in next step.
2,Use the Authorization Code to Request an Access Token:
3,We can leverage the access token for authorizing the resource REST API:
--update1--
To create an app-only without user ui application, you need to follow client_credentials flow, shown in https://msdn.microsoft.com/en-us/library/azure/dn645543.aspx.
And to your authorization issue, you need to assign a Owner role for a written permission. you can leverage azure-cli to do this.
Install the
Azure-CLI.
Connect to the
Azure-CLI.
Authenticate to your Service Principal using the Azure-CLI.
And in the 4th step in this section, you need to change Reader to Owner,
like
azure role assignment create --objectId 47193a0a-63e4-46bd-9bee-6a9f6f9c03cb -o Owner -c /subscriptions/{subscriptionId}/ to assign a written permission.

SugarCRM and Laravel : custom Authentication driver

I'm currently developing an app using Laravel. What I want to do, is to link this app to a SugarCRM app.
A simple workflow could be this:
User arrives to the app (Laravel app), enters its credentials
-> Credentials are sent to SugarCRM
-> if credentials are ok, the user is logged into the Laravel app.
Long story short, SugarCRM is used for the authentication to my Laravel App.
To do this, I developed a custom driver to my Laravel app.
The problem is:
If I quote the Laravel doc about custom Auth driver:
retrieveByCredentials: This method should not attempt to do any password validation or authentication.
Laravel Auth system requires to check first if the user exists in the base, with "no attempt to do any password validation or authentication".
But to do any kind of request to SugarCRM, I must authenticate first.
How should I deal with this without writing too dirty code?
What the docs mean there is that function shouldn't validate or authenticate credentials for your application. So if that function is called it shouldn't log that user in, but just return their credentials.
Its fine to authenticate to your external service so you can interact with their API.

Categories