11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License.
33
4+ using System ;
45using System . IO ;
56using System . Text ;
67using System . Windows ;
@@ -13,16 +14,45 @@ namespace active_directory_b2c_wpf
1314 /// </summary>
1415 public partial class App : Application
1516 {
16- private static readonly string Tenant = "fabrikamb2c.onmicrosoft.com" ;
17- private static readonly string AzureAdB2CHostname = "fabrikamb2c.b2clogin.com" ;
17+ /// <summary>
18+ /// B2C tenant name
19+ /// </summary>
20+ private static readonly string TenantName = "fabrikamb2c" ;
21+ private static readonly string Tenant = $ "{ TenantName } .onmicrosoft.com";
22+ private static readonly string AzureAdB2CHostname = $ "{ TenantName } .b2clogin.com";
23+
24+ /// <summary>
25+ /// ClientId for the application which initiates the login functionality (this app)
26+ /// </summary>
1827 private static readonly string ClientId = "841e1190-d73a-450c-9d68-f5cf16b78e81" ;
28+
29+ /// <summary>
30+ /// Should be one of the choices on the Azure AD B2c / [This App] / Authentication blade
31+ /// </summary>
1932 private static readonly string RedirectUri = "https://fabrikamb2c.b2clogin.com/oauth2/nativeclient" ;
33+
34+ /// <summary>
35+ /// From Azure AD B2C / UserFlows blade
36+ /// </summary>
2037 public static string PolicySignUpSignIn = "b2c_1_susi" ;
2138 public static string PolicyEditProfile = "b2c_1_edit_profile" ;
2239 public static string PolicyResetPassword = "b2c_1_reset" ;
2340
41+ /// <summary>
42+ /// Note: AcquireTokenInteractive will fail to get the AccessToken if "Admin Consent" has not been granted to this scope. To achieve this:
43+ ///
44+ /// 1st: Azure AD B2C / App registrations / [API App] / Expose an API / Add a scope
45+ /// 2nd: Azure AD B2C / App registrations / [This App] / API Permissions / Add a permission / My APIs / [API App] / Select & Add Permissions
46+ /// 3rd: Azure AD B2C / App registrations / [This App] / API Permissions / ... (next to add a permission) / Grant Admin Consent for [tenant]
47+ /// </summary>
2448 public static string [ ] ApiScopes = { "https://fabrikamb2c.onmicrosoft.com/helloapi/demo.read" } ;
49+
50+ /// <summary>
51+ /// URL for API which will receive the bearer token corresponding to this authentication
52+ /// </summary>
2553 public static string ApiEndpoint = "https://fabrikamb2chello.azurewebsites.net/hello" ;
54+
55+ // Shouldn't need to change these:
2656 private static string AuthorityBase = $ "https://{ AzureAdB2CHostname } /tfp/{ Tenant } /";
2757 public static string AuthoritySignUpSignIn = $ "{ AuthorityBase } { PolicySignUpSignIn } ";
2858 public static string AuthorityEditProfile = $ "{ AuthorityBase } { PolicyEditProfile } ";
@@ -35,18 +65,16 @@ static App()
3565 PublicClientApp = PublicClientApplicationBuilder . Create ( ClientId )
3666 . WithB2CAuthority ( AuthoritySignUpSignIn )
3767 . WithRedirectUri ( RedirectUri )
38- . WithLogging ( Log , LogLevel . Info , false ) // don't log PII details on a regular basis
68+ . WithLogging ( Log , LogLevel . Info , false ) // don't log P(ersonally) I(dentifiable) I(nformation) details on a regular basis
3969 . Build ( ) ;
4070
4171 TokenCacheHelper . Bind ( PublicClientApp . UserTokenCache ) ;
4272 }
73+
4374 private static void Log ( LogLevel level , string message , bool containsPii )
4475 {
45- string logs = ( $ "{ level } { message } ") ;
46- StringBuilder sb = new StringBuilder ( ) ;
47- sb . Append ( logs ) ;
48- File . AppendAllText ( System . Reflection . Assembly . GetExecutingAssembly ( ) . Location + ".msalLogs.txt" , sb . ToString ( ) ) ;
49- sb . Clear ( ) ;
76+ string logs = $ "{ level } { message } { Environment . NewLine } ";
77+ File . AppendAllText ( System . Reflection . Assembly . GetExecutingAssembly ( ) . Location + ".msalLogs.txt" , logs ) ;
5078 }
5179 }
5280}
0 commit comments