%3CLINGO-SUB%20id%3D%22lingo-sub-1563740%22%20slang%3D%22en-US%22%3EAdding%20Azure%20AD%20B2C%20Login%20to%20a%20Hybrid%20Mobile%20App%20Using%20Ionic%20Auth%20Connect%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1563740%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EAzure%20Active%20Directory%20B2C%20(Azure%20AD%20B2C)%20is%20a%20great%20way%20to%20enable%20secure%20authentication%20for%20your%20users%20across%20mobile%20and%20web%20--%20from%20basic%20sign-in%20and%20sign-out%2C%20to%20profile%20management%20and%20more.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EWhile%20Azure%20AD%20B2C%20is%20designed%20to%20work%20well%20on%20any%20iOS%20or%20Android%20phone%20or%20tablet%2C%20integrating%20with%20any%20auth%20provider%20can%20be%20particularly%20tricky%20on%20a%20mobile%20device%2C%20particularly%20if%20you%E2%80%99re%20building%20a%20%E2%80%9Chybrid%E2%80%9D%20mobile%20app%20using%20something%20like%20Cordova%20or%20Capacitor.%20Issues%20like%20secure%20token%20storage%2C%20Man-In-The-Middle%20attacks%2C%20and%20timely%20security%20updates%20can%20be%20troublesome%2C%20and%20create%20risks%20if%20not%20handled%20properly.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThat%E2%80%99s%20why%20the%20Ionic%20team%20designed%20Auth%20Connect.%20%3CA%20href%3D%22https%3A%2F%2Fionicframework.com%2Fauth-connect%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EIonic%20Auth%20Connect%3C%2FA%3E%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3Bmakes%20it%20easy%20to%20add%20secure%20authentication%20to%20any%20hybrid%20mobile%20app%20running%20on%20iOS%2C%20Android%2C%20or%20the%20web.%20Using%20a%20simple%2C%20powerful%20API%2C%20it%20handles%20logging%20in%20and%2For%20registering%20a%20user%20with%20an%20authentication%20provider%20(such%20as%20Azure%20Active%20Directory)%20using%20industry-standard%20OAuth%2FOpenId%20Connect.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1295241008%22%20id%3D%22toc-hId--1295241008%22%3E%3CSTRONG%3EGetting%20Started%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CP%3E%3CSPAN%3EIn%20this%20tutorial%2C%20we%E2%80%99ll%20add%20login%2Flogout%20functionality%20to%20a%20basic%20Ionic%20app%20by%20integrating%20Ionic%20Auth%20Connect.%20There%E2%80%99s%20only%20a%20few%20steps%20required%20to%20implement%20Auth%20Connect%20with%20Azure%20AD%20B2C%20in%20an%20Ionic%20app%3A%20configure%20Azure%20AD%20B2C%2C%20install%20Auth%20Connect%20in%20an%20Ionic%20app%2C%20and%20configure%20Auth%20Connect%20to%20use%20Azure%20AD%20B2C.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ETo%20begin%2C%20clone%20%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fionic-team%2Fdemo-authconnect-azureb2c%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%3CSPAN%3Ethis%20repository%3C%2FSPAN%3E%3C%2FA%3E%3CSPAN%3E%20and%20follow%20along.%20The%20%E2%80%9Cstart%E2%80%9D%20folder%20contains%20the%20basic%20structure%20of%20the%20app%20that%20we%E2%80%99ll%20make%20changes%20to%20and%20the%20%E2%80%9Ccompleted%E2%80%9D%20folder%20contains%20the%20finished%20app%20as%20a%20reference%20point%20if%20needed.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ENOTE%3A%20%3C%2FSTRONG%3E%3CSPAN%3EAn%20%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fionicframework.com%2Fdocs%2Fenterprise%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%3CSPAN%3EIonic%20Native%20Enterprise%20Edition%3C%2FSPAN%3E%3C%2FA%3E%3CSPAN%3E%20key%20is%20required%20in%20order%20to%20install%20and%20use%20the%20Ionic%20Auth%20Connect%20plugin.%20Ionic%20Native%20Enterprise%20features%20a%20library%20of%20Premier%20plugins%20and%20solutions%20that%20are%20fully%20supported%20and%20maintained%20by%20the%20Ionic%20team%2C%20with%20access%20to%20Ionic%20experts%20and%20a%20guaranteed%20response%20SLA%20to%20mission-critical%20app%20development.%20If%20you%20are%20interested%20in%20acquiring%20a%20key%20or%20learning%20more%2C%20please%20contact%20us%20%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fionicframework.com%2Fenterprise%2Fcontact%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%3CSPAN%3Ehere%3C%2FSPAN%3E%3C%2FA%3E%3CSPAN%3E.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ETo%20see%20what%20Ionic%20Auth%20Connect%20looks%20like%20in%20action%2C%20%3CA%20href%3D%22https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dv-LuS6aiRDo%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eview%20this%20short%20video%3C%2FA%3E.%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EAfter%20cloning%20the%20code%2C%20do%20the%20following%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSPAN%3E1.%20Install%20the%20Ionic%20CLI%3A%26nbsp%3B%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Enpm%20install%20-g%20%40ionic%2Fcli%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSPAN%3E2.%20In%20a%20terminal%2C%20change%20directory%20into%20the%20%E2%80%9Cstart%E2%80%9D%20folder%20in%20the%20repository%3A%26nbsp%3B%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Ecd%20demo-authconnect-azureb2c%2Fstart%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E3.%20Run%20%3CSTRONG%3Enpm%20install%3C%2FSTRONG%3E.%20NOTE%3A%20This%20will%20fail%20if%20an%20Ionic%20Native%20key%20hasn't%20been%20registered.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E4.%20Run%20%3CSTRONG%3Eionic%20serve%3C%2FSTRONG%3E%26nbsp%3Bto%20build%20and%20serve%20the%20app%20locally%20in%20a%20web%20browser.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--604679534%22%20id%3D%22toc-hId--604679534%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22toc-hId-1882833299%22%20id%3D%22toc-hId-1882833299%22%3E%3CSPAN%3EThe%20Reference%20App%3C%2FSPAN%3E%3C%2FH3%3E%0A%3CP%3E%3CSPAN%3EThe%20Ionic%20app%20is%20a%20modified%20version%20of%20a%20blank%20Angular%20starter%20project.%20It%20consists%20of%20two%20pages%3A%20the%20Home%20page%20displays%20the%20signed-in%20user's%20details%20(which%20will%20be%20retrieved%20from%20Azure%20AD%20B2C)%20and%20the%20Login%20page%20protects%20the%20Home%20page%20from%20unauthorized%20access.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1872330195%22%20id%3D%22toc-hId-1872330195%22%3E%3CSPAN%3EAzure%20Active%20Directory%20B2C%20Configuration%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EBefore%20integrating%20Auth%20Connect%20into%20the%20Ionic%20app%2C%20you%E2%80%99ll%20need%20to%20get%20Azure%20Active%20Directory%20(AD)%20B2C%20up%20and%20running.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSTRONG%3ENote%3A%3C%2FSTRONG%3E%20For%20complete%20information%20on%20configuring%20Azure%20AD%2C%20consult%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Factive-directory-b2c%2Foverview%3FWT.mc_id%3Dionicauthconnect-techcommunity-masoucou%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eofficial%20B2C%20documentation%3C%2FA%3E%20which%20includes%20tutorials%20on%20creating%20a%20B2C%20tenant%2C%20registering%20applications%2C%20and%20more.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1732075627%22%20id%3D%22toc-hId--1732075627%22%3E%3CSPAN%3ECreate%20an%20Azure%20AD%20B2C%20Tenant%3C%2FSPAN%3E%3C%2FH3%3E%0A%3CP%3E%3CSPAN%3EIf%20you%20don't%20have%20one%2C%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Factive-directory-b2c%2Ftutorial-create-tenant%3FWT.mc_id%3Dionicauthconnect-techcommunity-masoucou%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ecreate%20a%20new%20B2C%20tenant%3C%2FA%3E.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-755437206%22%20id%3D%22toc-hId-755437206%22%3E%3CSPAN%3ERegister%20an%20Application%3C%2FSPAN%3E%3C%2FH3%3E%0A%3CP%3E%3CSPAN%3ESign%20into%20the%20%3CA%20href%3D%22https%3A%2F%2Fportal.azure.com%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20Portal%3C%2FA%3E%20then%20navigate%20to%20the%20%3CSTRONG%3EAzure%20AD%20B2C%3C%2FSTRONG%3E%26nbsp%3Bservice%20page.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EBegin%20by%20creating%20a%20new%20Application%20under%20Manage%20-%20App%20registrations%20-%20New%20registration.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22azureb2c-register-app.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F210084i8253C4918F94B48E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22azureb2c-register-app.png%22%20alt%3D%22azureb2c-register-app.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EGive%20your%20app%20a%20new%20name%2C%20then%20select%20the%20Supported%20Account%20Types.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EWith%20that%20in%20hand%2C%20set%20the%20Redirect%20URI.%20Choose%20%E2%80%9CPublic%20client%2Fnative%20(mobile%20%26amp%3B%20desktop)%E2%80%9D%20-%20we%E2%80%99ll%20add%20web%20support%20in%20a%20separate%20step.%20Then%2C%20fill%20in%20the%20text%20field%20value%20with%20your%20globally%20unique%20App%20Id%2C%20which%20is%20used%20both%20in%20the%20Azure%20configuration%20as%20well%20as%20the%20native%20mobile%20app%E2%80%99s%20configuration.%20Typically%2C%20this%20takes%20the%20form%20of%20%3CSTRONG%3Ecompany-AppName%3C%2FSTRONG%3E%26nbsp%3Bor%20reverse%20DNS%20style%20-%20%3CSTRONG%3Ecom.company.app%3C%2FSTRONG%3E.%20Use%20the%20formula%20%E2%80%9CuniqueId%3A%2F%2Fpage%E2%80%9D.%20After%20the%20app%20user%20signs%20into%20Azure%20AD%2C%20this%20tells%20Auth%20Connect%20which%20page%20to%20redirect%20to%20in%20your%20app.%20While%20any%20page%20can%20be%20used%2C%20in%20this%20example%20we%E2%80%99ll%20use%20the%20Login%20page%2C%20such%20as%20%3CSTRONG%3Ecom.company.app%3A%2F%2Flogin%3C%2FSTRONG%3E.%20Click%20the%20register%20button%20to%20create%20the%20app.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1052017257%22%20id%3D%22toc-hId--1052017257%22%3E%3CSPAN%3EAdd%20Web%20Platform%3C%2FSPAN%3E%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EWith%20the%20app%20created%2C%20navigate%20to%20Manage%20-%20Authentication.%20Click%20the%20%E2%80%9CAdd%20a%20Platform%E2%80%9D%20button.%20Under%20Web%20applications%2C%20choose%20%E2%80%9Csingle-page%20application.%E2%80%9D%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EUnder%20Redirect%20URIs%2C%20specify%20a%20web%20URL.%20In%20this%20example%2C%20for%20local%20testing%2C%20we%E2%80%99ll%20use%20http%3A%2F%2Flocalhost%3A8100%2F%20along%20with%20the%20name%20of%20your%20app's%20core%20login%20page%20(typically%2C%20%3CSTRONG%3Elogin%3C%2FSTRONG%3E).%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20data-unlink%3D%22true%22%3E%3CSPAN%3ENext%2C%20under%20Logout%20URL%2C%20specify%20a%20web%20URL%20to%20redirect%20to%20once%20the%20user%20has%20logged%20out%20of%20your%20app.%20Again%2C%20for%20local%20testing%2C%20specify%20%3C%2FSPAN%3E%3CSPAN%3E%3CSTRONG%3Ehttps%3A%2F%2Flocalhost%3A8100%2F%3C%2FSTRONG%3E%3C%2FSPAN%3E%26nbsp%3B%3CSPAN%3Ealong%20with%20the%20name%20of%20the%20logout%20page%20(typically%20%3CSTRONG%3Elogout%3C%2FSTRONG%3E).%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EFinally%2C%20under%20Implicit%20Grant%2C%20toggle%20%E2%80%9CAccess%20tokens.%E2%80%9D%20Click%20the%20Configure%20button%20to%20save.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22azureb2c-spa.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F210085i8F449F8C6CEAB1EF%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22azureb2c-spa.png%22%20alt%3D%22azureb2c-spa.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EBack%20on%20the%20Authentication%20page%2C%20look%20under%20the%20Single-page%20application%20settings.%20Click%20the%20%E2%80%9CAdd%20URI%E2%80%9D%20button%20to%20add%20additional%20Redirect%20URIs%2C%20including%20those%20for%20other%20environments%20like%20staging%20or%20production.%20Click%20Save%20when%20ready.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22azureb2c-web-redirecturis.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F210086i0888044B2613498C%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22azureb2c-web-redirecturis.png%22%20alt%3D%22azureb2c-web-redirecturis.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-1435495576%22%20id%3D%22toc-hId-1435495576%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22toc-hId--371958887%22%20id%3D%22toc-hId--371958887%22%3E%3CSPAN%3EExpose%20an%20API%3C%2FSPAN%3E%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ENavigate%20to%20the%20%E2%80%9CExpose%20an%20API%E2%80%9D%20page.%20Click%20%E2%80%9CAdd%20a%20scope%E2%80%9D%2C%20then%20for%20the%20Scope%20name%2C%20provide%20a%20value%20such%20as%20%E2%80%9Cuser_impersonation.%E2%80%9D%20For%20the%20display%20name%20and%20description%20fields%2C%20add%20details%20describing%20that%20this%20is%20for%20authenticating%20your%20users.%20Set%20the%20state%20to%20enabled%20then%20click%20the%20%E2%80%9CAdd%20scope%E2%80%9D%20button.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-2115553946%22%20id%3D%22toc-hId-2115553946%22%3E%3CSPAN%3EConfigure%20API%20Permissions%3C%2FSPAN%3E%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ENext%2C%20we%20need%20to%20authorize%20our%20app%20so%20it%20can%20connect%20to%20Azure%20B2C%20and%20retrieve%20user%20profile%20information%20alongside%20login%20credentials.%20Navigate%20to%20the%20API%20Permissions%20page%20then%20click%20the%20%E2%80%9CAdd%20a%20permission%E2%80%9D%20button.%20Under%20%E2%80%9CSelect%20an%20API%E2%80%9D%2C%20choose%20%E2%80%9CMy%20APIs%E2%80%9D%20then%20click%20the%20name%20of%20the%20B2C%20app%20we%E2%80%99re%20currently%20configuring.%20Next%2C%20select%20the%20%E2%80%9Cuser_impersonation%E2%80%9D%20permission%20(or%20whatever%20name%20you%20labeled%20it%20in%20the%20previous%20step)%20then%20click%20the%20%E2%80%9CAdd%20permissions%E2%80%9D%20button.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ESave%20the%20application%2C%20then%20click%20on%20the%20newly%20added%20permission%20row.%20Click%20the%20%E2%80%9CGrant%20admin%20consent%20for%20%5Byour%20organization%20name%5D%E2%80%9D%20button%20then%20choose%20%E2%80%9CYes.%E2%80%9D%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%E2%80%83%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22azureb2c-api-permissions.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F210089iF8336823F7926668%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22azureb2c-api-permissions.png%22%20alt%3D%22azureb2c-api-permissions.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EClick%20on%20the%20%E2%80%9Cuser_impersonation%E2%80%9D%20permission%20row%20again%20to%20open%20the%20modal%20window%2C%20then%20click%20to%20copy%20the%20link%20that%20is%20displayed.%20Note%20this%20URL%2C%20because%20it%20will%20be%20used%20as%20part%20of%20Auth%20Connect%E2%80%99s%20%E2%80%9Cscopes%E2%80%9D%20property%20later.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22azureb2c-scopes-link.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F210090i5E27D0F564B32032%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22azureb2c-scopes-link.png%22%20alt%3D%22azureb2c-scopes-link.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--387063996%22%20id%3D%22toc-hId--387063996%22%3E%3CSPAN%3ECreate%20User%20Flows%20(Policies)%3C%2FSPAN%3E%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ECreate%20at%20least%20one%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Factive-directory-b2c%2Ftutorial-create-user-flows%3FWT.mc_id%3Dionicauthconnect-techcommunity-masoucou%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EUser%20Flow%3C%2FA%3E%2C%20the%20series%20of%20pages%20that%20define%20the%20entire%20authentication%20experience%20for%20your%20app.%20At%20a%20minimum%2C%20create%20a%20%3CSTRONG%3ESign%20up%20and%20sign%20in%3C%2FSTRONG%3E%26nbsp%3Bflow.%20Once%20the%20User%20Flow%20has%20been%20created%2C%20select%20it%20from%20the%20User%20Flow%20list%2C%20then%20click%20%22Run%20user%20flow%22%20from%20the%20Overview%20tab.%20Note%20the%20URL%20at%20the%20top%20of%20the%20page%2C%20used%20to%20configure%20Auth%20Connect's%20%3CSTRONG%3EDiscovery%20URL%3C%2FSTRONG%3E%26nbsp%3Bproperty.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EAzure%20AD%20B2C%20is%20now%20ready%20to%20use%20with%20Auth%20Connect.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%E2%80%83%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1971366118%22%20id%3D%22toc-hId-1971366118%22%3E%3CSPAN%3EInstall%20Auth%20Connect%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EAuth%20Connect%20works%20on%20the%20web%20or%20on%20mobile.%20For%20deploying%20to%20mobile%2C%20we%E2%80%99ll%20use%20Capacitor%2C%20Ionic%E2%80%99s%20cross-platform%20native%20runtime%20for%20building%20native%20mobile%20and%20web%20apps%2C%20using%20JavaScript%2C%20HTML%2C%20and%20CSS%2C%20with%20one%20shared%20codebase.%20Learn%20more%20about%20the%20project%20and%20how%20to%20deploy%20this%20Ionic%20app%20to%20mobile%20%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fcapacitorjs.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%3CSPAN%3Ehere%3C%2FSPAN%3E%3C%2FA%3E%3CSPAN%3E.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EAdding%20Capacitor%20is%20easy%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Eionic%20integrations%20enable%20capacitor%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ERun%20the%20following%20command%20to%20install%20the%20Auth%20Connect%20plugin.%20For%20the%20%3CSTRONG%3EAUTH_URL_SCHEME%3C%2FSTRONG%3E%26nbsp%3Bvariable%2C%20use%20the%20globally%20unique%20App%20Id%20(ex%3A%20%3CSTRONG%3Ecom.company.app%3C%2FSTRONG%3E)%20you%20decided%20on%20when%20configuring%20the%20Azure%20AD%20app%20above.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Enpm%20install%20%40ionic-enterprise%2Fauth%20--variable%20AUTH_URL_SCHEME%3Dcom.company.app%0Anpx%20cap%20sync%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-163911655%22%20id%3D%22toc-hId-163911655%22%3E%3CSPAN%3EConfigure%20Auth%20Connect%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EConfiguring%20Auth%20Connect%20involves%20two%20steps%3A%20adding%20configuration%20details%20into%20the%20app%20from%20your%20Azure%20AD%20tenant%20and%20implementing%20login%2Flogout%20functionality.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1514460089%22%20id%3D%22toc-hId--1514460089%22%3E%3CSPAN%3EAzure%20Configuration%20Details%3C%2FSPAN%3E%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ESince%20the%20Azure%20AD%20B2C%20app%20will%20support%20different%20values%20per%20environment%20(typically%20staging%2C%20QA%2C%20production%2C%20etc.)%20we%20can%20support%20that%20in%20the%20Ionic%20app%20using%20Angular%E2%80%99s%20%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fangular.io%2Fguide%2Fbuild%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%3CSPAN%3Eenvironments%3C%2FSPAN%3E%3C%2FA%3E%3CSPAN%3E.%20Open%20%3CSTRONG%3Esrc%2Fenvironments%2Fenvironment.ts%3C%2FSTRONG%3E%26nbsp%3Bthen%20add%20the%20following.%20We%E2%80%99ll%20begin%20with%20a%20web-based%20configuration%20since%20it%E2%80%99s%20easier%20to%20build%20and%20test%20locally%20in%20a%20browser%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3Eimport%20%7B%20IonicAuthOptions%20%7D%20from%20'%40ionic-enterprise%2Fauth'%3B%0A%0Aexport%20const%20azureWebConfig%20%3A%20IonicAuthOptions%20%3D%20%7B%0A%20%20%2F%2F%20the%20auth%20provider%0A%20%20authConfig%3A%20'azure'%2C%0A%20%20%2F%2F%20The%20platform%20which%20we%20are%20running%20on%0A%20%20platform%3A%20'web'%2C%0A%20%20%2F%2F%20client%20or%20application%20id%20for%20provider%0A%20%20clientID%3A%20'FILL_IN'%2C%0A%20%20%2F%2F%20the%20discovery%20url%20for%20the%20provider%0A%20%20%2F%2F%20OpenID%20configuration%0A%20%20discoveryUrl%3A%20'FILL_IN'%2C%0A%20%20%2F%2F%20the%20URI%20to%20redirect%20to%20after%20log%20in%0A%20%20redirectUri%3A%20'http%3A%2F%2Flocalhost%3A8100%2Flogin'%2C%0A%20%20%2F%2F%20requested%20scopes%20from%20provider%0A%20%20scope%3A%20'openid%20offline_access%20email%20profile%20FILL_IN'%2C%0A%20%20%2F%2F%20the%20URL%20to%20redirect%20to%20after%20log%20out%0A%20%20logoutUrl%3A%20'http%3A%2F%2Flocalhost%3A8100%2Flogin'%2C%0A%20%20%2F%2F%20Show%20provider%20login%20in%20either%20current%20window%20or%20new%20tab%0A%20%20implicitLogin%3A%20%22CURRENT%22%0A%7D%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ESome%20of%20these%20%60IonicAuthOptions%60%20values%20are%20unique%20and%20must%20be%20set%20based%20on%20the%20Azure%20AD%20app%20that%20we%20just%20created%20above%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E*%20%3CSTRONG%3Eplatform%3C%2FSTRONG%3E%3A%20Use%20%E2%80%9Cweb%E2%80%9D%20if%20running%20as%20a%20PWA%20or%20%E2%80%9Ccapacitor%E2%80%9D%20when%20the%20app%20is%20deployed%20as%20an%20iOS%20or%20Android%20app.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E*%20%3CSTRONG%3EclientID%3C%2FSTRONG%3E%3A%20Your%20app%E2%80%99s%20_Application%20(client)%20ID_%2C%20found%20on%20the%20Overview%20page.%20Example%3A%20cebbb0be-d578-4bbd-9712-4b0fe05c06aa%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E*%20%3CSTRONG%3EredirectUri%3C%2FSTRONG%3E%3A%20The%20URI%20to%20redirect%20to%20after%20the%20user%20has%20logged%20in.%20Since%20we%E2%80%99re%20testing%20locally%20in%20a%20browser%2C%20use%20%E2%80%9C%3C%2FSPAN%3E%3CA%20href%3D%22http%3A%2F%2Flocalhost%3A8100%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%3CSPAN%3Ehttp%3A%2F%2Flocalhost%3A8100%2F%3C%2FSPAN%3E%3C%2FA%3E%3CSPAN%3Elogin%E2%80%9D%20since%20this%20is%20what%20%60ionic%20serve%60%20runs%20on.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E*%20%3CSTRONG%3ElogoutUrl%3C%2FSTRONG%3E%3A%20The%20URI%20to%20redirect%20to%20after%20the%20user%20has%20logged%20out.%20Again%2C%20use%20%E2%80%9C%3C%2FSPAN%3E%3CA%20href%3D%22http%3A%2F%2Flocalhost%3A8100%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%3CSPAN%3Ehttp%3A%2F%2Flocalhost%3A8100%2F%3C%2FSPAN%3E%3C%2FA%3E%3CSPAN%3E%E2%80%9D.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThe%20%3CSTRONG%3Escope%3C%2FSTRONG%3E%26nbsp%3Bproperty%20is%20used%20to%20unlock%20access%20to%20protected%20resources%2C%20such%20as%20read%2Fwrite%20permissions.%20There%E2%80%99s%20a%20variety%20of%20attributes%20available%3B%20an%20example%20looks%20like%3A%20%E2%80%9Copenid%20offline_access%20email%20profile%E2%80%9D.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EIn%20addition%20to%20the%20values%20above%2C%20add%20the%20Full%20Scope%20Value%20link%20created%20earlier%20to%20the%20%60scope%60%20property.%20To%20find%20it%20in%20the%20Azure%20AD%20B2C%20portal%2C%20navigate%20to%20the%20%E2%80%9CExpose%20an%20API%E2%80%9D%20page%20then%20click%20on%20the%20Scope%20you%20defined%20earlier.%20In%20the%20modal%20window%2C%20copy%20the%20link%20that%20appears%20under%20%E2%80%9CScope%20name.%E2%80%9D%20All%20together%2C%20it%20will%20look%20similar%20to%20this%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3Escope%3A%20'openid%20offline_access%20email%20profile%20https%3A%2F%2Forgname.onmicrosoft.com%2Fapi%2Fuser_impersonation'%2C%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThe%20%3CSTRONG%3EdiscoveryUrl%3C%2FSTRONG%3E%26nbsp%3Bcan%20be%20found%20by%20navigating%20to%20the%20main%20Azure%20AD%20B2C%20page%20-%26gt%3B%20Policies%20-%26gt%3B%20User%20flows%20-%26gt%3B%20%5BSelect%20User%20Flow%5D%20-%26gt%3B%20Overview%20tab%20-%26gt%3B%20Run%20user%20flow%20button.%20The%20discovery%20link%20is%20at%20the%20top%20of%20the%20page%20and%20will%20look%20like%20the%20following%20format%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20data-unlink%3D%22true%22%3E%3CSTRONG%3Ehttps%3A%2F%2FB2C-TENANT-NAME.b2clogin.com%2FB2C-TENANT-NAME.onmicrosoft.com%2Fv2.0%2F.well-known%2Fopenid-configuration%3Fp%3DPOLICY-NAME%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EWhere%20%3CSTRONG%3EB2C-TENANT-NAME%3C%2FSTRONG%3E%26nbsp%3Bis%20your%20tenant%20name%20and%20the%20%3CSTRONG%3EPOLICY-NAME%3C%2FSTRONG%3E%26nbsp%3Bis%20the%20name%20of%20the%20User%20Flow%20created%20earlier.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThe%20native%20mobile%20configuration%20is%20almost%20the%20same%20as%20the%20web.%20Make%20a%20copy%20of%20the%20web%20configuration%20then%20change%20the%20redirect%20and%20logout%20urls.%20Use%20the%20same%20AUTH_URL_SCHEME%20variable%20value%20(App%20Id)%20from%20when%20the%20Auth%20Connect%20plugin%20was%20installed.%20For%20example%2C%20%E2%80%9Ccom.company.app%3A%2F%2F%E2%80%9D%20plus%20the%20name%20of%20the%20Login%20page.%20Change%20the%20platform%20to%20%E2%80%9Ccapacitor%E2%80%9D%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3Eexport%20const%20azureNativeConfig%20%3A%20IonicAuthOptions%20%3D%20%7B%0A%20%20platform%3A%20'capacitor'%2C%0A%20%20redirectUrl%3A%20'com.company.app%3A%2F%2Flogin'%2C%0A%20%20logoutUrl%3A%20'com.company.app%3A%2F%2Flogout'%0A%20%0A%20%20%2F%2F%20snip%20-%20other%20variables%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-973052744%22%20id%3D%22toc-hId-973052744%22%3E%3CSTRONG%3ECreate%20an%20Authentication%20Service%20for%20Login%20Functionality%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EWith%20Azure%20AD%20environment%20configurations%20added%20to%20the%20Ionic%20app%2C%20we%20can%20now%20leverage%20them%20in%20an%20%3CSTRONG%3EAuthenticationService%26nbsp%3B%3C%2FSTRONG%3Eclass%20that%20encapsulates%20Azure%20AD%20and%20Ionic%20Auth%20Connect%E2%80%99s%20login%20functionality.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EGenerate%20this%20class%20using%20the%20%3CSTRONG%3Eionic%20generate%3C%2FSTRONG%3E%26nbsp%3Bcommand%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Eionic%20generate%20service%20services%2Fauthentication%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EOpen%20up%20%3CSTRONG%3Esrc%2Fapp%2Fservices%2Fauthentication.service.ts%3C%2FSTRONG%3E%26nbsp%3Band%20import%20Auth%20Connect%2C%20RxJs%20(for%20tracking%20login%20status%20changes)%2C%20and%20the%20Azure%20AD%20configuration%20objects%20we%20just%20created%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3Eimport%20%7B%20Injectable%20%7D%20from%20'%40angular%2Fcore'%3B%0Aimport%20%7B%20Platform%20%7D%20from%20'%40ionic%2Fangular'%3B%0Aimport%20%7B%20IonicAuth%20%7D%20from%20'%40ionic-enterprise%2Fauth'%3B%0Aimport%20%7B%20Subject%2C%20Observable%20%7D%20from%20'rxjs'%3B%0Aimport%20%7B%20azureNativeConfig%2C%20azureWebConfig%20%7D%20from%20'..%2F..%2Fenvironments%2Fenvironment'%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ENext%2C%20extend%20the%20IonicAuth%20class%20in%20order%20to%20gain%20access%20to%20Auth%20Connect%E2%80%99s%20functionality%2C%20and%20in%20the%20constructor%2C%20instantiate%20it%20with%20the%20proper%20Azure%20configuration%20object.%20Using%20Ionic%E2%80%99s%20%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fionicframework.com%2Fdocs%2Fangular%2Fplatform%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%3CSPAN%3EPlatform%20API%3C%2FSPAN%3E%3C%2FA%3E%3CSPAN%3E%2C%20we%20can%20dynamically%20choose%20which%20configuration%20to%20use%20based%20on%20whether%20the%20app%20is%20running%20on%20the%20web%20or%20a%20mobile%20device.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3Eexport%20class%20AuthenticationService%20extends%20IonicAuth%20%7B%0A%20%20constructor(platform%3A%20Platform)%20%7B%0A%20%20%20%20%2F%2F%20Determine%20whether%20to%20run%20on%20mobile%20or%20the%20web%0A%20%20%20%20const%20selectedConfig%20%3D%20platform.is('hybrid')%20%3F%20azureNativeConfig%20%3A%20azureWebConfig%3B%0A%20%20%20%20super(selectedConfig)%3B%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EImplementing%20login%20functionality%20is%20quite%20simple%20-%20we%20define%20our%20own%20login%20method%20then%20call%20Auth%20Connect%E2%80%99s%20login%20method.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3Easync%20login()%3A%20Promise%3CVOID%3E%20%7B%0A%20%20await%20super.login()%3B%0A%7D%3C%2FVOID%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EUpon%20successful%20login%2C%20Auth%20Connect%20calls%20the%20%60onLoginSuccess%60%20event%2C%20which%20we%20can%20override%20here%20to%20run%20any%20additional%20logic%20we%20need.%20In%20this%20case%2C%20we%20can%20emit%20an%20RxJs%20event%20when%20the%20login%20status%20changes%20(either%20logged%20in%20or%20logged%20out)%20then%20react%20accordingly%20(direct%20the%20user%20into%20the%20app%20or%20back%20to%20the%20Login%20page).%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3EonLoginSuccess()%20%7B%0A%20%20%20%20this._loginStatusChanged.next(true)%3B%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EDefine%20the%20status%20change%20observable%20right%20below%20the%20class%20definition%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3E%20%2F%2F%20Emit%20event%20when%20login%20status%20changes%20%0A%20%20private%20_loginStatusChanged%3A%20Subject%3CBOOLEAN%3E%3B%0A%0A%20%20get%20loginStatusChanged()%3A%20Observable%3CBOOLEAN%3E%20%7B%0A%20%20%20%20return%20this._loginStatusChanged.asObservable()%3B%0A%20%20%7D%3C%2FBOOLEAN%3E%3C%2FBOOLEAN%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ETo%20detect%20and%20act%20on%20the%20login%20status%20changing%2C%20head%20over%20to%20%60app.component.ts%60%20in%20%60src%2Fapp%60.%20Import%20the%20AuthenticationService%20class%2C%20then%20subscribe%20to%20the%20status%20change%20observable%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3Eimport%20%7B%20AuthenticationService%20%7D%20from%20'.%2Fservices%2Fauthentication.service'%3B%0A%0A%2F%2F%20snip%0A%0Aconstructor(%0A%0A%20%20%20%20private%20auth%3A%20AuthenticationService%2C%0A%20%20%20%20private%20navController%3A%20NavController%2C%0A%20%20%20%20private%20platform%3A%20Platform%0A%20%20)%20%7B%0A%0A%20%20%20%20this.initializeApp()%3B%0A%0A%20%20%20%20this.auth.loginStatusChanged.subscribe(authenticated%20%3D%26gt%3B%20%0A%20%20%20%20%20%20%20%20%20this.handleAuthChange(authenticated))%3B%0A%20%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ENext%2C%20add%20a%20method%20that%20inspects%20the%20status%20of%20the%20login%20attempt.%20If%20successful%2C%20redirect%20the%20user%20to%20the%20Home%20page%2C%20otherwise%2C%20remain%20on%20the%20Login%20page%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3Eprivate%20handleAuthChange(authenticated%3A%20boolean)%20%7B%0A%20%20%20%20if%20(authenticated)%20%7B%0A%20%20%20%20%20%20this.navController.navigateRoot(%5B'home'%5D)%3B%0A%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20this.navController.navigateRoot(%5B'login'%5D)%3B%0A%20%20%20%20%7D%0A%20%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThe%20last%20step%20is%20easy%3A%20leveraging%20the%20AuthenticationService%20from%20the%20Login%20page%20(%60src%2Fapp%2Flogin%2Flogin.page.ts%60).%20First%2C%20add%20a%20click%20handler%20to%20the%20Login%20button%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-html%22%3E%3CCODE%3E%3CION-BUTTON%3E%0A%20%20%20Log%20in%0A%3C%2FION-BUTTON%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ENext%2C%20add%20a%20new%20method%20to%20call%20the%20AuthenticationService%E2%80%99s%20login%20method%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3Easync%20login()%20%7B%0A%20%20await%20this.authService.login()%3B%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EJust%20one%20last%20step%20required.%20When%20running%20as%20a%20web%20app%2C%20the%20user%20will%20be%20redirected%20to%20the%20Azure%20AD%20sign-in%20page.%20After%20successful%20sign-in%2C%20they%E2%80%99ll%20be%20sent%20back%20to%20the%20Ionic%20app%20and%20since%20this%20is%20a%20%E2%80%9Cfresh%E2%80%9D%20load%20of%20the%20page%2C%20we%20need%20to%20pass%20the%20access%20token%20along%20to%20Auth%20Connect.%20To%20do%20so%2C%20pass%20the%20browser%E2%80%99s%20url%20to%20Auth%20Connect%E2%80%99s%20%60handleCallback%60%20function%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3Easync%20ngOnInit()%20%7B%0A%20%20%20%20if%20(window.location.hash)%20%7B%0A%20%20%20%20%20%20%20%20await%20this.authService.handleCallback(window.location.href)%3B%0A%20%20%20%20%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EOnce%20handleCallback%20completes%2C%20Auth%20Connect%20will%20call%20%60onLoginSuccess()%60%20in%20the%20AuthenticationService%20class%2C%20which%20triggers%20the%20login%20status%20change%20event%2C%20ultimately%20permitting%20the%20user%20access%20to%20the%20Home%20page.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThat%E2%80%99s%20it!%20Click%20the%20Login%20button%20in%20the%20browser%2C%20sign%20in%20using%20your%20Azure%20AD%20B2C%20credentials%2C%20then%20you%20should%20be%20redirected%20to%20the%20Home%20app.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--834401719%22%20id%3D%22toc-hId--834401719%22%3E%3CSTRONG%3EView%20Azure%20AD%20User%20Details%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ELogging%20in%20is%20nice%2C%20but%20what%20if%20we%20took%20it%20one%20step%20further%20by%20displaying%20some%20of%20the%20Azure%20AD%20user%E2%80%99s%20profile%20details%20on%20the%20Home%20page%3F%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EBack%20over%20in%20the%20AuthenticationService%2C%20declare%20a%20new%20method%20to%20retrieve%20the%20user%E2%80%99s%20profile%20info%20from%20Azure.%20Access%20all%20information%20via%20Auth%20Connect%E2%80%99s%20%60getIdToken%60%20function%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3Easync%20getUserInfo()%20%7B%0A%20%20%20%20const%20idToken%20%3D%20await%20this.getIdToken()%3B%0A%20%20%20%20if%20(!idToken)%20%7B%0A%20%20%20%20%20%20return%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20let%20email%20%3D%20idToken.email%3B%0A%0A%20%20%20%20if%20(idToken.emails%20instanceof%20Array)%20%7B%0A%20%20%20%20%20%20email%20%3D%20idToken.emails%5B0%5D%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20return%20%7B%0A%20%20%20%20%20%20id%3A%20idToken.sub%2C%0A%20%20%20%20%20%20email%3A%20email%2C%0A%20%20%20%20%20%20firstName%3A%20idToken.given_name%2C%0A%20%20%20%20%20%20lastName%3A%20idToken.family_name%2C%0A%20%20%20%20%20%20picture%3A%20%22assets%2Fuser-placeholder.jpg%22%0A%20%20%20%20%7D%3B%0A%20%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ENext%2C%20over%20in%20the%20Home%20page%20(%60src%2Fapp%2Fhome%2Fhome.page.ts%60)%2C%20make%20the%20call%20to%20%60getUserInfo%60%20when%20the%20page%20loads%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3Euser%3A%20any%3B%0A%0Aconstructor(private%20authService%3A%20AuthenticationService)%20%7B%20%7D%0A%0Aasync%20ngOnInit()%20%7B%0A%20%20%20%20this.user%20%3D%20await%20this.authService.getUserInfo()%3B%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ETo%20complete%20this%2C%20update%20the%20Home%20page%E2%80%99s%20HTML%20template%20so%20that%20it%20now%20displays%20the%20user%E2%80%99s%20profile%20info%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-html%22%3E%3CCODE%3E%3CION-CONTENT%3E%0A%20%20%3CDIV%20class%3D%22ion-padding%22%3E%0A%20%20%20%20%3CDIV%20align%3D%22center%22%3E%0A%20%20%20%20%20%20%3CION-AVATAR%3E%0A%20%20%20%20%20%20%20%20%3CIMG%20src%3D%22%7B%7B%20user.picture%20%7D%7D%22%20%2F%3E%0A%20%20%20%20%20%20%3C%2FION-AVATAR%3E%0A%0A%20%20%20%20%20%20%3CP%3E%7B%7B%20user.firstName%7D%7D%20%7B%7B%20user.lastName%20%7D%7D%3C%2FP%3E%20%0A%20%20%20%20%20%20%3CP%3E%7B%7B%20user.email%20%7D%7D%3C%2FP%3E%0A%20%20%20%20%3C%2FDIV%3E%0A%0A%20%20%20%20%3CION-BUTTON%20expand%3D%22block%22%3ELog%20out%3C%2FION-BUTTON%3E%0A%20%20%3C%2FDIV%3E%0A%3C%2FION-CONTENT%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EIf%20you%E2%80%99re%20still%20running%20%60ionic%20serve%60%2C%20save%20all%20files%2C%20then%20the%20page%20should%20reload%2C%20displaying%20your%20Azure%20AD%20user%20profile%20details.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-1653111114%22%20id%3D%22toc-hId-1653111114%22%3E%3CSTRONG%3EImplementing%20Log%20Out%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThe%20last%20step%20is%20to%20add%20logout%20functionality.%20Since%20we%E2%80%99re%20already%20in%20the%20Home%20page%20code%2C%20add%20a%20new%20function%20that%20calls%20Auth%20Connect%E2%80%99s%20%60logout%60%20function%20directly%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3Easync%20logout()%20%7B%0A%20%20%20%20await%20this.authService.logout()%3B%0A%20%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EBack%20over%20in%20AuthenticationService%2C%20implement%20Auth%20Connect%E2%80%99s%20%E2%80%9ConLogout%E2%80%9D%20event%2C%20which%20fires%20once%20it%20has%20successfully%20logged%20out%20the%20current%20user.%20All%20the%20app%20needs%20to%20do%20is%20fire%20the%20login%20status%20changed%20event%2C%20passing%20%E2%80%9Cfalse%E2%80%9D%20to%20indicate%20that%20the%20user%20is%20no%20longer%20logged%20in%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3EonLogout()%20%7B%0A%20%20%20%20this._loginStatusChanged.next(false)%3B%0A%20%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ERecall%20that%20this%20event%20will%20be%20caught%20over%20in%20%60app.component.ts%60%2C%20and%20since%20%E2%80%9Cauthenticated%E2%80%9D%20is%20now%20false%2C%20the%20user%20will%20be%20redirected%20to%20the%20Login%20page%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3Eprivate%20handleAuthChange(authenticated%3A%20boolean)%20%7B%0A%20%20%20%20if%20(authenticated)%20%7B%0A%20%20%20%20%20%20this.navController.navigateRoot(%5B'home'%5D)%3B%0A%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20this.navController.navigateRoot(%5B'login'%5D)%3B%0A%20%20%20%20%7D%0A%20%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EReload%20the%20page%2C%20click%20the%20Logout%20button%2C%20and%20you%20should%20be%20signed%20out%20then%20redirected%20to%20the%20Login%20page.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--283426068%22%20id%3D%22toc-hId--283426068%22%3E%3CSPAN%3EWhat's%20Next%3F%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EIn%20just%20a%20few%20steps%2C%20we%20added%20Azure%20AD%20B2C%20authentication%20to%20an%20Ionic%20app%2C%20with%20complete%20login%20and%20logout%20functionality.%20With%20Auth%20Connect%20now%20in%20place%2C%20there%20are%20many%20paths%20to%20go%20from%20here.%20You%20can%20further%20tweak%20the%20Azure%20AD%20user%20experience%20(such%20as%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Factive-directory-b2c%2Ftutorial-customize-ui%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ecustomizing%20the%20user%20interface%3C%2FA%3E%3C%2FSPAN%3E%3CSPAN%3E)%20or%20begin%20%3CA%20href%3D%22https%3A%2F%2Fionicframework.com%2Fdocs%2Fenterprise%2Fauth-connect%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Etesting%20Auth%20Connect%3C%2FA%3E%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3Bin%20a%20native%20app%20right%20away.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--2090880531%22%20id%3D%22toc-hId--2090880531%22%3E%3CSPAN%3EAbout%20Ionic%20Auth%20Connect%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EAuth%20Connect%20is%20built%20and%20maintained%20by%20the%20Ionic%20team.%26nbsp%3B-ERR%3AREF-NOT-FOUND-Ionic%26nbsp%3Bmakes%20tools%20and%20services%20that%20empower%20web%20developers%20to%20deliver%20stunning%20native%20mobile%20and%20web%20applications%2C%20using%20the%20web%20tools%2C%20libraries%2C%20and%20frameworks%20that%20they%20know%20and%20love.%20Our%20cross-platform%20native%20runtime%2C%26nbsp%3B-ERR%3AREF-NOT-FOUND-Capacitor%2C%20provides%20a%20secure%20way%20to%20deliver%20web-based%20applications%20on%20a%20mobile%20device.%20When%20coupled%20with%20Ionic%E2%80%99s%20Auth%20Connect%20solution%2C%20implementing%20single%20sign-on%20in%20web%20applications%20is%20even%20easier.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EHappy%20app%20building!%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1563740%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22active-directory-ionic-ms-techcomm.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F211932iFA924784F51EE26E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22active-directory-ionic-ms-techcomm.png%22%20alt%3D%22active-directory-ionic-ms-techcomm.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ELearn%20how%20to%20use%20Ionic%20Auth%20Connect%20and%20Azure%20AD%20B2C%20to%20secure%20your%20hybrid%20mobile%20app%20(Cordova%20or%20Capacitor).%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1563740%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20Active%20Directory%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMobile%20Apps%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWeb%20Apps%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Visitor

Azure Active Directory B2C (Azure AD B2C) is a great way to enable secure authentication for your users across mobile and web -- from basic sign-in and sign-out, to profile management and more. 

 

While Azure AD B2C is designed to work well on any iOS or Android phone or tablet, integrating with any auth provider can be particularly tricky on a mobile device, particularly if you’re building a “hybrid” mobile app using something like Cordova or Capacitor. Issues like secure token storage, Man-In-The-Middle attacks, and timely security updates can be troublesome, and create risks if not handled properly.

 

That’s why the Ionic team designed Auth Connect. Ionic Auth Connect makes it easy to add secure authentication to any hybrid mobile app running on iOS, Android, or the web. Using a simple, powerful API, it handles logging in and/or registering a user with an authentication provider (such as Azure Active Directory) using industry-standard OAuth/OpenId Connect.

 

Getting Started

In this tutorial, we’ll add login/logout functionality to a basic Ionic app by integrating Ionic Auth Connect. There’s only a few steps required to implement Auth Connect with Azure AD B2C in an Ionic app: configure Azure AD B2C, install Auth Connect in an Ionic app, and configure Auth Connect to use Azure AD B2C.

 

To begin, clone this repository and follow along. The “start” folder contains the basic structure of the app that we’ll make changes to and the “completed” folder contains the finished app as a reference point if needed.

 

NOTE: An Ionic Native Enterprise Edition key is required in order to install and use the Ionic Auth Connect plugin. Ionic Native Enterprise features a library of Premier plugins and solutions that are fully supported and maintained by the Ionic team, with access to Ionic experts and a guaranteed response SLA to mission-critical app development. If you are interested in acquiring a key or learning more, please contact us here.

 

To see what Ionic Auth Connect looks like in action, view this short video. 

 

After cloning the code, do the following:

1. Install the Ionic CLI: 

 

 

 

 

npm install -g @ionic/cli

 

 

 

 

2. In a terminal, change directory into the “start” folder in the repository: 

 

 

 

 

cd demo-authconnect-azureb2c/start

 

 

 

 

3. Run npm install. NOTE: This will fail if an Ionic Native key hasn't been registered.

 

4. Run ionic serve to build and serve the app locally in a web browser.

 

The Reference App

The Ionic app is a modified version of a blank Angular starter project. It consists of two pages: the Home page displays the signed-in user's details (which will be retrieved from Azure AD B2C) and the Login page protects the Home page from unauthorized access. 

 

Azure Active Directory B2C Configuration

 

Before integrating Auth Connect into the Ionic app, you’ll need to get Azure Active Directory (AD) B2C up and running.

 

Note: For complete information on configuring Azure AD, consult the official B2C documentation which includes tutorials on creating a B2C tenant, registering applications, and more.

Create an Azure AD B2C Tenant

If you don't have one, create a new B2C tenant.

 

Register an Application

Sign into the Azure Portal then navigate to the Azure AD B2C service page.

 

Begin by creating a new Application under Manage - App registrations - New registration.

 

azureb2c-register-app.png

 

Give your app a new name, then select the Supported Account Types.

 

With that in hand, set the Redirect URI. Choose “Public client/native (mobile & desktop)” - we’ll add web support in a separate step. Then, fill in the text field value with your globally unique App Id, which is used both in the Azure configuration as well as the native mobile app’s configuration. Typically, this takes the form of company-AppName or reverse DNS style - com.company.app. Use the formula “uniqueId://page”. After the app user signs into Azure AD, this tells Auth Connect which page to redirect to in your app. While any page can be used, in this example we’ll use the Login page, such as com.company.app://login. Click the register button to create the app.

 

Add Web Platform

 

With the app created, navigate to Manage - Authentication. Click the “Add a Platform” button. Under Web applications, choose “single-page application.” 

 

Under Redirect URIs, specify a web URL. In this example, for local testing, we’ll use http://localhost:8100/ along with the name of your app's core login page (typically, login). 

 

Next, under Logout URL, specify a web URL to redirect to once the user has logged out of your app. Again, for local testing, specify https://localhost:8100/ along with the name of the logout page (typically logout).

 

Finally, under Implicit Grant, toggle “Access tokens.” Click the Configure button to save.

 

azureb2c-spa.png

 

 

Back on the Authentication page, look under the Single-page application settings. Click the “Add URI” button to add additional Redirect URIs, including those for other environments like staging or production. Click Save when ready.

 

azureb2c-web-redirecturis.png

 

 

Expose an API

 

Navigate to the “Expose an API” page. Click “Add a scope”, then for the Scope name, provide a value such as “user_impersonation.” For the display name and description fields, add details describing that this is for authenticating your users. Set the state to enabled then click the “Add scope” button.

 

Configure API Permissions

 

Next, we need to authorize our app so it can connect to Azure B2C and retrieve user profile information alongside login credentials. Navigate to the API Permissions page then click the “Add a permission” button. Under “Select an API”, choose “My APIs” then click the name of the B2C app we’re currently configuring. Next, select the “user_impersonation” permission (or whatever name you labeled it in the previous step) then click the “Add permissions” button.

 

Save the application, then click on the newly added permission row. Click the “Grant admin consent for [your organization name]” button then choose “Yes.”

azureb2c-api-permissions.png

Click on the “user_impersonation” permission row again to open the modal window, then click to copy the link that is displayed. Note this URL, because it will be used as part of Auth Connect’s “scopes” property later.

 

azureb2c-scopes-link.png

 

Create User Flows (Policies)

 

Create at least one User Flow, the series of pages that define the entire authentication experience for your app. At a minimum, create a Sign up and sign in flow. Once the User Flow has been created, select it from the User Flow list, then click "Run user flow" from the Overview tab. Note the URL at the top of the page, used to configure Auth Connect's Discovery URL property.

 

Azure AD B2C is now ready to use with Auth Connect.

Install Auth Connect

 

Auth Connect works on the web or on mobile. For deploying to mobile, we’ll use Capacitor, Ionic’s cross-platform native runtime for building native mobile and web apps, using JavaScript, HTML, and CSS, with one shared codebase. Learn more about the project and how to deploy this Ionic app to mobile here.

 

Adding Capacitor is easy:

 

 

 

 

ionic integrations enable capacitor

 

 

 

 

 

Run the following command to install the Auth Connect plugin. For the AUTH_URL_SCHEME variable, use the globally unique App Id (ex: com.company.app) you decided on when configuring the Azure AD app above.

 

 

 

 

npm install @ionic-enterprise/auth --variable AUTH_URL_SCHEME=com.company.app
npx cap sync

 

 

 

 

Configure Auth Connect

 

Configuring Auth Connect involves two steps: adding configuration details into the app from your Azure AD tenant and implementing login/logout functionality.

 

Azure Configuration Details

 

Since the Azure AD B2C app will support different values per environment (typically staging, QA, production, etc.) we can support that in the Ionic app using Angular’s environments. Open src/environments/environment.ts then add the following. We’ll begin with a web-based configuration since it’s easier to build and test locally in a browser:

 

 

 

 

 

import { IonicAuthOptions } from '@ionic-enterprise/auth';

export const azureWebConfig : IonicAuthOptions = {
  // the auth provider
  authConfig: 'azure',
  // The platform which we are running on
  platform: 'web',
  // client or application id for provider
  clientID: 'FILL_IN',
  // the discovery url for the provider
  // OpenID configuration
  discoveryUrl: 'FILL_IN',
  // the URI to redirect to after log in
  redirectUri: 'http://localhost:8100/login',
  // requested scopes from provider
  scope: 'openid offline_access email profile FILL_IN',
  // the URL to redirect to after log out
  logoutUrl: 'http://localhost:8100/login',
  // Show provider login in either current window or new tab
  implicitLogin: "CURRENT"
};

 

 

 

 

 

Some of these `IonicAuthOptions` values are unique and must be set based on the Azure AD app that we just created above:

 

* platform: Use “web” if running as a PWA or “capacitor” when the app is deployed as an iOS or Android app.

* clientID: Your app’s _Application (client) ID_, found on the Overview page. Example: cebbb0be-d578-4bbd-9712-4b0fe05c06aa

* redirectUri: The URI to redirect to after the user has logged in. Since we’re testing locally in a browser, use “http://localhost:8100/login” since this is what `ionic serve` runs on. 

* logoutUrl: The URI to redirect to after the user has logged out. Again, use “http://localhost:8100/”. 

 

The scope property is used to unlock access to protected resources, such as read/write permissions. There’s a variety of attributes available; an example looks like: “openid offline_access email profile”.

 

In addition to the values above, add the Full Scope Value link created earlier to the `scope` property. To find it in the Azure AD B2C portal, navigate to the “Expose an API” page then click on the Scope you defined earlier. In the modal window, copy the link that appears under “Scope name.” All together, it will look similar to this:

 

 

 

 

 

scope: 'openid offline_access email profile https://orgname.onmicrosoft.com/api/user_impersonation',

 

 

 

 

 

The discoveryUrl can be found by navigating to the main Azure AD B2C page -> Policies -> User flows -> [Select User Flow] -> Overview tab -> Run user flow button. The discovery link is at the top of the page and will look like the following format:

 

https://B2C-TENANT-NAME.b2clogin.com/B2C-TENANT-NAME.onmicrosoft.com/v2.0/.well-known/openid-configuration?p=POLICY-NAME 

 

Where B2C-TENANT-NAME is your tenant name and the POLICY-NAME is the name of the User Flow created earlier.

 

The native mobile configuration is almost the same as the web. Make a copy of the web configuration then change the redirect and logout urls. Use the same AUTH_URL_SCHEME variable value (App Id) from when the Auth Connect plugin was installed. For example, “com.company.app://” plus the name of the Login page. Change the platform to “capacitor”:

 

 

 

 

 

export const azureNativeConfig : IonicAuthOptions = {
  platform: 'capacitor',
  redirectUrl: 'com.company.app://login',
  logoutUrl: 'com.company.app://logout'
	
  // snip - other variables
}

 

 

 

 

 

Create an Authentication Service for Login Functionality

 

With Azure AD environment configurations added to the Ionic app, we can now leverage them in an AuthenticationService class that encapsulates Azure AD and Ionic Auth Connect’s login functionality.

 

Generate this class using the ionic generate command:

 

 

 

 

 

ionic generate service services/authentication

 

 

 

 

 

Open up src/app/services/authentication.service.ts and import Auth Connect, RxJs (for tracking login status changes), and the Azure AD configuration objects we just created:

 

 

 

 

 

import { Injectable } from '@angular/core';
import { Platform } from '@ionic/angular';
import { IonicAuth } from '@ionic-enterprise/auth';
import { Subject, Observable } from 'rxjs';
import { azureNativeConfig, azureWebConfig } from '../../environments/environment';

 

 

 

 

 

Next, extend the IonicAuth class in order to gain access to Auth Connect’s functionality, and in the constructor, instantiate it with the proper Azure configuration object. Using Ionic’s Platform API, we can dynamically choose which configuration to use based on whether the app is running on the web or a mobile device.

 

 

 

 

 

export class AuthenticationService extends IonicAuth {
  constructor(platform: Platform) {
    // Determine whether to run on mobile or the web
    const selectedConfig = platform.is('hybrid') ? azureNativeConfig : azureWebConfig;
    super(selectedConfig);
}

 

 

 

 

 

Implementing login functionality is quite simple - we define our own login method then call Auth Connect’s login method.

 

 

 

 

 

async login(): Promise<void> {
  await super.login();
}

 

 

 

 

 

Upon successful login, Auth Connect calls the `onLoginSuccess` event, which we can override here to run any additional logic we need. In this case, we can emit an RxJs event when the login status changes (either logged in or logged out) then react accordingly (direct the user into the app or back to the Login page). 

 

 

 

 

 

onLoginSuccess() {
    this._loginStatusChanged.next(true);
}

 

 

 

 

 

Define the status change observable right below the class definition:

 

 

 

 

 

 // Emit event when login status changes 
  private _loginStatusChanged: Subject<boolean>;

  get loginStatusChanged(): Observable<boolean> {
    return this._loginStatusChanged.asObservable();
  }

 

 

 

 

 

To detect and act on the login status changing, head over to `app.component.ts` in `src/app`. Import the AuthenticationService class, then subscribe to the status change observable:

 

 

 

 

 

import { AuthenticationService } from './services/authentication.service';

// snip

constructor(

    private auth: AuthenticationService,
    private navController: NavController,
    private platform: Platform
  ) {

    this.initializeApp();

    this.auth.loginStatusChanged.subscribe(authenticated => 
         this.handleAuthChange(authenticated));
  }

 

 

 

 

 

Next, add a method that inspects the status of the login attempt. If successful, redirect the user to the Home page, otherwise, remain on the Login page:

 

 

 

 

 

private handleAuthChange(authenticated: boolean) {
    if (authenticated) {
      this.navController.navigateRoot(['home']);
    } else {
      this.navController.navigateRoot(['login']);
    }
  }

 

 

 

 

 

The last step is easy: leveraging the AuthenticationService from the Login page (`src/app/login/login.page.ts`). First, add a click handler to the Login button:

 

 

 

 

 

<ion-button (click)="login()" strong shape="round">
   Log in
</ion-button>

 

 

 

 

 

Next, add a new method to call the AuthenticationService’s login method:

 

 

 

 

 

async login() {
  await this.authService.login();
}

 

 

 

 

 

Just one last step required. When running as a web app, the user will be redirected to the Azure AD sign-in page. After successful sign-in, they’ll be sent back to the Ionic app and since this is a “fresh” load of the page, we need to pass the access token along to Auth Connect. To do so, pass the browser’s url to Auth Connect’s `handleCallback` function:

 

 

 

 

 

async ngOnInit() {
    if (window.location.hash) {
        await this.authService.handleCallback(window.location.href);
    }
}

 

 

 

 

 

Once handleCallback completes, Auth Connect will call `onLoginSuccess()` in the AuthenticationService class, which triggers the login status change event, ultimately permitting the user access to the Home page.

 

That’s it! Click the Login button in the browser, sign in using your Azure AD B2C credentials, then you should be redirected to the Home app.

 

View Azure AD User Details

 

Logging in is nice, but what if we took it one step further by displaying some of the Azure AD user’s profile details on the Home page?

 

Back over in the AuthenticationService, declare a new method to retrieve the user’s profile info from Azure. Access all information via Auth Connect’s `getIdToken` function:

 

 

 

 

 

async getUserInfo() {
    const idToken = await this.getIdToken();
    if (!idToken) {
      return;
    }

    let email = idToken.email;

    if (idToken.emails instanceof Array) {
      email = idToken.emails[0];
    }

    return {
      id: idToken.sub,
      email: email,
      firstName: idToken.given_name,
      lastName: idToken.family_name,
      picture: "assets/user-placeholder.jpg"
    };
  }

 

 

 

 

 

Next, over in the Home page (`src/app/home/home.page.ts`), make the call to `getUserInfo` when the page loads:

 

 

 

 

 

user: any;

constructor(private authService: AuthenticationService) { }

async ngOnInit() {
    this.user = await this.authService.getUserInfo();
}

 

 

 

 

 

To complete this, update the Home page’s HTML template so that it now displays the user’s profile info:

 

 

 

 

 

<ion-content>
  <div class="ion-padding">
    <div align="center" *ngIf="user">
      <ion-avatar>
        <img src="{{ user.picture }}">
      </ion-avatar>

      <p>{{ user.firstName}} {{ user.lastName }}</p> 
      <p>{{ user.email }}</p>
    </div>

    <ion-button expand="block" (click)="logout();" style="margin-top: 50px">Log out</ion-button>
  </div>
</ion-content>

 

 

 

 

 

If you’re still running `ionic serve`, save all files, then the page should reload, displaying your Azure AD user profile details.

Implementing Log Out

 

The last step is to add logout functionality. Since we’re already in the Home page code, add a new function that calls Auth Connect’s `logout` function directly:

 

 

 

 

 

async logout() {
    await this.authService.logout();
  }

 

 

 

 

 

 

Back over in AuthenticationService, implement Auth Connect’s “onLogout” event, which fires once it has successfully logged out the current user. All the app needs to do is fire the login status changed event, passing “false” to indicate that the user is no longer logged in:

 

 

 

 

 

onLogout() {
    this._loginStatusChanged.next(false);
  }

 

 

 

 

 

 

Recall that this event will be caught over in `app.component.ts`, and since “authenticated” is now false, the user will be redirected to the Login page:

 

 

 

 

 

private handleAuthChange(authenticated: boolean) {
    if (authenticated) {
      this.navController.navigateRoot(['home']);
    } else {
      this.navController.navigateRoot(['login']);
    }
  }

 

 

 

 

 

Reload the page, click the Logout button, and you should be signed out then redirected to the Login page. 

 

What's Next?

 

In just a few steps, we added Azure AD B2C authentication to an Ionic app, with complete login and logout functionality. With Auth Connect now in place, there are many paths to go from here. You can further tweak the Azure AD user experience (such as customizing the user interface) or begin testing Auth Connect in a native app right away.

 

About Ionic Auth Connect

 

Auth Connect is built and maintained by the Ionic team. Ionic makes tools and services that empower web developers to deliver stunning native mobile and web applications, using the web tools, libraries, and frameworks that they know and love. Our cross-platform native runtime, Capacitor, provides a secure way to deliver web-based applications on a mobile device. When coupled with Ionic’s Auth Connect solution, implementing single sign-on in web applications is even easier.

 

Happy app building!