A
A
Alexander2021-12-24 17:38:55
PHP
Alexander, 2021-12-24 17:38:55

How to configure UserProvider for Oauth(azure)?

I'm trying to set up authorization using Azure AD
Installed the HWIOAuthBundle
set up the creds

#config/packages/hwi_oauth.yaml
hwi_oauth:
    # list of names of the firewalls in which this bundle is active, this setting MUST be set
    firewall_names: [azure]
    resource_owners:
        microsoft:
            type:                azure
            client_id:           '%env(MICROSOFT_CLIENT_ID)%'
            client_secret:       '%env(MICROSOFT_CLIENT_SECRET)%'
            scope:                User.Read offline_access

            options:
                application: common

added route
#config/routes.yaml
microsoft_login:
    path: /oauth-login/check-microsoft

#config/routes/hwi_oauth_routing.yaml
hwi_oauth_redirect:
    resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
    prefix:   /connect

hwi_oauth_connect:
    resource: "@HWIOAuthBundle/Resources/config/routing/connect.xml"
    prefix:   /connect

hwi_oauth_login:
    resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
    prefix:   /oauth-login

Also configured the firewall and specified the provider
#config/packages/security.yaml
security:
    enable_authenticator_manager: true
    # https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
    password_hashers:
        Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
    # https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
    encoders:
        App\Entity\User:
            algorithm: bcrypt
    providers:
        users_in_memory: { memory: null }
        entity_provider:
            entity:
                class: App\Entity\User
                property: username
        microsoft_user_provider:
            id: app.custom.user_provider
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            pattern: ^/
            provider: entity_provider
            form_login:
                login_path: login_admin
                check_path: login_admin
                default_target_path: admin_contract_list
                always_use_default_target_path: true
            logout:
                path: logout_admin
                target: login_admin

        azure:
            pattern: ^/
            oauth:
                resource_owners:
                    microsoft: "/oauth-login/check-microsoft"
                login_path: /oauth-login
                use_forward: false
                failure_path: /oauth-login
                oauth_user_provider:
                    service:  mf.oauth_aware.user_provider.service
                provider: microsoft_user_provider

    access_control:
#      - { path: ^/, roles: ROLE_USER }
        - { path: ^/oauth-login, roles: PUBLIC_ACCESS }


As a result, I get a link where you can go to login (hwi_oauth_service_redirect) I
successfully go through the authentication process and after a redirect from the authorization server I get to the redirect_uri specified in the Azure AD
settings The response arrives with the parameters code, state
http://localhost:8001/oauth-login/check-microsoft?code=M.R3_BAY.a40cbc79.....&state=eyJjc3JmX3Rva2VuIjoiMjhiMzZ....


Here I absolutely do not understand what to do
how to process this response.
I understand that the user provider, which I specified in the settings, should somehow connect here. But I don’t understand how
at all ....

PS If someone wants to write how stupid I am, you don’t have to work, I myself know :)
If someone’s religious feelings, "desecrating the Symphony" with my misunderstanding - sorry, I did not have the goal of hurting the feelings of believers :)
If someone can help the suffering - help, I have been suffering for two days

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri Kolesnikov, 2015-08-28
@yurikoles

Learn to ask questions.

K
kos-kokos, 2015-08-31
@kos-kokos

Faced the same problem. I had a problem with the css shapes plugin. Turned it off and everything worked again.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question