22{
33 using Microsoft . AspNetCore . Http ;
44 using Microsoft . AspNetCore . Mvc ;
5- using Sqlbi . Bravo . Infrastructure ;
6- using Sqlbi . Bravo . Infrastructure . Configuration ;
7- using Sqlbi . Bravo . Infrastructure . Models . PBICloud ;
85 using Sqlbi . Bravo . Infrastructure . Services . PowerBI ;
9- using Sqlbi . Bravo . Models ;
6+ using Sqlbi . Bravo . Models . Authentication ;
107 using Sqlbi . Bravo . Services ;
11- using System . Collections . Generic ;
12- using System . Linq ;
13- using System . Net . Mime ;
14- using System . Threading ;
15- using System . Threading . Tasks ;
168
179 /// <summary>
1810 /// Authentication controller
2113 [ Route ( "auth/[action]" ) ]
2214 [ ApiController ]
2315 [ ProducesResponseType ( StatusCodes . Status400BadRequest , Type = typeof ( ProblemDetails ) ) ]
24- public class AuthenticationController : ControllerBase
16+ public sealed class AuthenticationController (
17+ IPBICloudAuthenticationService pbicloudAuthenticationService ,
18+ IPBICloudService pbicloudService ,
19+ IAuthenticationService authenticationService ) : ControllerBase
2520 {
26- private readonly IAuthenticationService _authenticationService ;
27- private readonly IPBICloudService _pbicloudService ;
28-
29- public AuthenticationController ( IAuthenticationService authenticationService , IPBICloudService pbicloudService )
30- {
31- _authenticationService = authenticationService ;
32- _pbicloudService = pbicloudService ;
33- }
21+ private readonly IAuthenticationService _authenticationService = authenticationService ;
22+ private readonly IPBICloudAuthenticationService _pbicloudAuthenticationService = pbicloudAuthenticationService ;
23+ private readonly IPBICloudService _pbicloudService = pbicloudService ;
3424
3525 /// <summary>
36- /// TODO
26+ /// Returns the list of available PowerBI cloud environments for the specified email account.
3727 /// </summary>
3828 /// <response code="200">Status200OK - Success</response>
3929 [ HttpGet ]
40- [ ActionName ( "powerbi/ GetEnvironments" ) ]
30+ [ ActionName ( "GetEnvironments" ) ]
4131 [ Produces ( MediaTypeNames . Application . Json ) ]
42- [ ProducesResponseType ( StatusCodes . Status200OK , Type = typeof ( IEnumerable < IPBICloudEnvironment > ) ) ]
32+ [ ProducesResponseType ( StatusCodes . Status200OK , Type = typeof ( GetEnvironmentsResponse ) ) ]
4333 [ ProducesDefaultResponseType ]
44- public async Task < IActionResult > GetPBICloudEnvironmentsAsync ( string userPrincipalName , CancellationToken cancellationToken )
34+ public async Task < IActionResult > GetEnvironmentsAsync (
35+ [ FromQuery ] GetEnvironmentsRequest request ,
36+ CancellationToken cancellationToken )
4537 {
46- var environments = await _authenticationService . GetPBICloudEnvironmentsAsync ( userPrincipalName , cancellationToken ) ;
47- return Ok ( environments ) ;
38+ var environments = await _pbicloudAuthenticationService . GetEnvironmentsAsync (
39+ request . Email ,
40+ cancellationToken ) ;
41+
42+ var response = new GetEnvironmentsResponse ( environments ) ;
43+ return Ok ( response ) ;
4844 }
4945
5046 /// <summary>
5147 /// Attempts to authenticate and acquire an access token for the account to access the PowerBI cloud services
5248 /// </summary>
5349 /// <response code="200">Status200OK - Success</response>
5450 [ HttpPost ]
55- [ ActionName ( "powerbi/ SignIn" ) ]
51+ [ ActionName ( "SignIn" ) ]
5652 [ Produces ( MediaTypeNames . Application . Json ) ]
57- [ ProducesResponseType ( StatusCodes . Status200OK , Type = typeof ( IBravoAccount ) ) ]
53+ [ ProducesResponseType ( StatusCodes . Status200OK , Type = typeof ( SignInResponse ) ) ]
5854 [ ProducesDefaultResponseType ]
59- public async Task < IActionResult > PBICloudSignInAsync ( PBICloudAuthenticationRequest request , CancellationToken cancellationToken )
55+ public async Task < IActionResult > SignInAsync (
56+ SignInRequest request ,
57+ CancellationToken cancellationToken )
6058 {
61- await _authenticationService . PBICloudSignInAsync ( request . UserPrincipalName ! , request . Environment ! , cancellationToken ) ;
62- return Ok ( _authenticationService . PBICloudAuthentication . Account ) ;
59+ await _authenticationService . PBICloudSignInAsync (
60+ request . Email ,
61+ request . Environment . ToModel ( ) ,
62+ cancellationToken ) ;
63+
64+ var response = new SignInResponse ( _authenticationService . PBICloudAuthentication . Account ) ;
65+ return Ok ( response ) ;
6366 }
6467
6568 /// <summary>
6669 /// Clear the token cache for all the accounts
6770 /// </summary>
6871 /// <response code="200">Status200OK - Success</response>
6972 [ HttpGet ]
70- [ ActionName ( "powerbi/ SignOut" ) ]
73+ [ ActionName ( "SignOut" ) ]
7174 [ ProducesResponseType ( StatusCodes . Status200OK ) ]
7275 [ ProducesDefaultResponseType ]
73- public async Task < IActionResult > PBICloudSignOutAsync ( CancellationToken cancellationToken )
76+ public async Task < IActionResult > SignOutAsync ( CancellationToken cancellationToken )
7477 {
7578 await _authenticationService . PBICloudSignOutAsync ( cancellationToken ) ;
7679 return Ok ( ) ;
@@ -89,7 +92,7 @@ public async Task<IActionResult> PBICloudSignOutAsync(CancellationToken cancella
8992 [ ProducesResponseType ( StatusCodes . Status404NotFound ) ]
9093 [ ProducesResponseType ( StatusCodes . Status401Unauthorized ) ]
9194 [ ProducesDefaultResponseType ]
92- public async Task < IActionResult > GetPBICloudAccountAvatarAsync ( CancellationToken cancellationToken )
95+ public async Task < IActionResult > GetUserAvatarAsync ( CancellationToken cancellationToken )
9396 {
9497 if ( await _authenticationService . IsPBICloudSignInRequiredAsync ( cancellationToken ) )
9598 return Unauthorized ( ) ;
0 commit comments