Impersonation in spring auth server and an microsoft entra Id

I want to implement impersonation functionality in my application, to bring support by an admin to end users. My architecture is the following:

1.- React app in front.

2.- Spring Resource Server. Is a REST API that react app call.

3.- Spring Auth Server that act as authorization server. This server is token issuer, and is auth client too, becuase use Microsoft EntraID for authenticate.

Here the configuration of 2.-Resource Server:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>spring.security.oauth2.resourceserver.jwt.issuer-uri: https://auth-server
</code>
<code>spring.security.oauth2.resourceserver.jwt.issuer-uri: https://auth-server </code>
spring.security.oauth2.resourceserver.jwt.issuer-uri: https://auth-server

Here the config of 3.- Auth Server:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>spring.security.oauth2:
authorizationserver:
issuer: https://auth-server
client:
react-client:
registration:
client-id: client-id
client-secret: secret
redirect-uris:
- https://react-app/redirect
client-authentication-methods:
- client_secret_basic
authorization-grant-types:
- authorization_code
- refresh_token
scopes:
- openid
- profile
- https://graph.microsoft.com/User.ReadBasic.All
client:
provider:
azure:
issuer-uri: https://login.microsoftonline.com/${azure.tenant-id}/v2.0
user-name-attribute: sub
registration:
my-client:
provider: azure
scope:
- openid
- profile
- email
redirect-uri: https://auth-server/login/oauth2/code/
</code>
<code>spring.security.oauth2: authorizationserver: issuer: https://auth-server client: react-client: registration: client-id: client-id client-secret: secret redirect-uris: - https://react-app/redirect client-authentication-methods: - client_secret_basic authorization-grant-types: - authorization_code - refresh_token scopes: - openid - profile - https://graph.microsoft.com/User.ReadBasic.All client: provider: azure: issuer-uri: https://login.microsoftonline.com/${azure.tenant-id}/v2.0 user-name-attribute: sub registration: my-client: provider: azure scope: - openid - profile - email redirect-uri: https://auth-server/login/oauth2/code/ </code>
spring.security.oauth2:
      authorizationserver:
        issuer: https://auth-server
        client:
          react-client:
            registration:
              client-id: client-id
              client-secret: secret
              redirect-uris:
                - https://react-app/redirect
              client-authentication-methods:
               - client_secret_basic
              authorization-grant-types:
                - authorization_code
                - refresh_token
              scopes:
                - openid
                - profile
                - https://graph.microsoft.com/User.ReadBasic.All
      client:
        provider:
          azure:
            issuer-uri: https://login.microsoftonline.com/${azure.tenant-id}/v2.0
            user-name-attribute: sub
        registration:
          my-client:
            provider: azure
            scope:
              - openid
              - profile
              - email
            redirect-uri: https://auth-server/login/oauth2/code/ 

With this configuration, all works well. The react app first call to auth server to get code:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>https://auth-server/oauth2/authorize
?client_id=client-id
&redirect_uri=https://react-app/redirect
&scope=openid
&response_type=code
&response_mode=form_post
&state=xxxxxxxxxxx
&nonce=xxxxxxxxxxx
</code>
<code>https://auth-server/oauth2/authorize ?client_id=client-id &redirect_uri=https://react-app/redirect &scope=openid &response_type=code &response_mode=form_post &state=xxxxxxxxxxx &nonce=xxxxxxxxxxx </code>
https://auth-server/oauth2/authorize 
?client_id=client-id
&redirect_uri=https://react-app/redirect 
&scope=openid 
&response_type=code 
&response_mode=form_post 
&state=xxxxxxxxxxx 
&nonce=xxxxxxxxxxx

Auth server call to Microsoft EntraID to login the user with her credentials.

Then with this code the app call to token endpoint to get a token:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>https://auth-server/oauth2/authorize
?grant_type=authorization_code
&code=mH09Ql0a_5RihuweHHDhdD3
&client_id=client-id
&client_secret=secreto
&redirect_uri=https://react-app/redirect
</code>
<code>https://auth-server/oauth2/authorize ?grant_type=authorization_code &code=mH09Ql0a_5RihuweHHDhdD3 &client_id=client-id &client_secret=secreto &redirect_uri=https://react-app/redirect </code>
https://auth-server/oauth2/authorize 
?grant_type=authorization_code
&code=mH09Ql0a_5RihuweHHDhdD3
&client_id=client-id
&client_secret=secreto
&redirect_uri=https://react-app/redirect

With this token react app know who is the user and can use this token to call Resource Server.

Now, I want to impersonate a user, and I don’t know how to do this.

I read that maybe need to use the token-exchange grant_type, that support Spring Security 6.3.0-M3.

I put urn:ietf:params:oauth:grant-type:token-exchange in authorization-grant-types, and works well if i have the token to put in subject_token. But, the problem is that the admin user don’t know the end-user token to inpersonate, only know her email that use to login in Microsoft Entra ID.

Any suggestion to impersonate a end-user with this flow?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật