Using Okta with Static Web Apps

Published May 13 2021 10:12 PM 2,320 Views
Microsoft

One of my favorite features of (the now General Available) Azure Static Web Apps (SWA) is that in the Standard Tier you can now provide a custom OpenID Connect (OIDC) provider. This gives you a lot more control over who can and can’t access your app.

In this post, I want to look at how we can use Okta and an OIDC provider for Static Web Apps.

For this, you’ll need an Okta account, so if you don’t already have one go sign up and maybe have a read of their docs, just so you’re across everything.

Creating a Static Web App

For this demo, we’ll use the React template, but what we’re covering isn’t specific to React, it’ll be applicable anywhere.

Once you’ve created your app, we’re going to need to setup a configuration file, so add staticwebapp.config.json to the repo root.

This config file is used for controlling a lot of things within our SWA, but the most important part for us is going to be the auth section. Let’s flesh out the skeleton for it:

 

{
    "auth": {
        "identityProviders": {
            "customOpenIdConnectProviders": {}
        }
    }
}

 

Great! Now it’s time to setup Okta.

Creating an Okta application

Log into the Okta dashboard and navigate through to the Applications section of the portal:

001.png

From here, we’re going to select Create App Integration and select OIDC - OpenID Connect for the Sign-on method and Web Application as the Application type. You might be tempted to select the SPA option, given that we’re creating a JavaScript web application, but the reason we don’t use that is that SWA’s auth isn’t handled by your application itself, it’s handled by the underlying Azure service, which is a “web application”, that then exposes the information out that you need.

002.png

Configure your Okta application

With your application created, it’s time to configure it. Give it a name, something that’ll make sense when you see it in the list of Okta applications, a logo if you desire, but leave the Grant type information alone, the defaults are configured for us just fine.

We are going to need to provide the application with some redirect options for login/logout, so that SWA will know you’ve logged in and can unpack the basic user information.

For the Sign-in redirect URIs you will need to add https://<hostname>/.auth/login/okta/callback and for Sign-out redirect URIs add https://<hostname>/.auth/logout/okta/callback. If you haven’t yet deployed to Azure, don’t worry about this step yet, we’ll do it once the SWA is created.

Quick note - the okta value here is going to be how we name the provider in the staticwebapp.config.json, so it can be anything you want, I just like to use the provider name so the config is easy to read.

Click Save, and it’s time to finish off our SWA config file.

003.png

Completing our settings

With our Okta application setup, it’s time to complete our config file so it can use it. We’ll add a new configuration under customOpenIdConnectProviders for Okta and it’ll contain two core pieces of information, the information on how to register the OIDC provider and some login information on how to talk to the provider.

Inside registration, we’ll add a clientIdSettingName field, which will point to an entry in the app settings that the SWA has. Next, we’ll need a clientCredential object that has clientSecretSettingName that is the entry for the OIDC client secret. Lastly, we’ll provide the openIdConnectConfiguration with a wellKnownOpenIdConfiguration endpoint that is https://<your_okta_domain>/.well-known//openid-configuration.

The config should now look like this:

 

{
    "auth": {
        "identityProviders": {
            "customOpenIdConnectProviders": {
                "okta": {
                    "registration": {
                        "clientIdSettingName": "OKTA_ID",
                        "clientCredential": {
                            "clientSecretSettingName": "OKTA_SECRET"
                        },
                        "openIdConnectConfiguration": {
                            "wellKnownOpenIdConfiguration": "https://dev-920852.okta.com/.well-known/openid-configuration"
                        }
                    }
                }
            }
        }
    }
}

 

I use OKTA_ID and OKTA_SECRET as the names of the items I’ll be putting into app settings.

All this information will tell SWA how to issue a request against the right application in Okta, but we still need to tell it how to make the request and handle the response. That’s what we use the login config for. With the login config, we provide a nameClaimType, which is a fully-qualified path to the claim that we want SWA to use as the userDetails field of the user info. Generally speaking, you’ll want this to be http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name, but if there’s a custom field in your response claims you want to use, make sure you provide that. The other bit of config we need here is what scopes to request from Okta. For SWA, you only need openid and profile as the scopes, unless you’re wanting to use a nameClaimType other than standard.

Let’s finish off our SWA config:

 

{
    "auth": {
        "identityProviders": {
            "customOpenIdConnectProviders": {
                "okta": {
                    "registration": {
                        "clientIdSettingName": "OKTA_ID",
                        "clientCredential": {
                            "clientSecretSettingName": "OKTA_SECRET"
                        },
                        "openIdConnectConfiguration": {
                            "wellKnownOpenIdConfiguration": "https://dev-920852.okta.com/.well-known/openid-configuration"
                        }
                    },
                    "login": {
                        "nameClaimType": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name",
                        "scopes": ["openid", "profile"]
                    }
                }
            }
        }
    }
}

 

With the config ready you can create the SWA in Azure and kick off a deployment (don’t forget to update the Okta app with the login/logout callbacks). When the resource is created in Azure, copy the Client ID and Client secret from Okta and create app settings in Azure using the names in your config and the values from Okta.

Using the provider

Once the provider is registered in the config file, it is usable just like the other providers SWA offers, with the login being /.auth/login/<provider_name>, which in this case the provider_name is okta. The user information will then be exposed as standard to both the web and API components.

If you’re building a React application, check out my React auth helper and for the API there is a companion.

Conclusion

I really like that with the GA of Static Web Apps we are now able to use custom OIDC providers with the platform. This makes it a lot easier to have controlled user access and integration with a more complex auth story when needed. Setting this up with Okta only takes a few lines of config.

You can check out a full code sample on my GitHub and a live demo here (but I’m not giving you my Okta credentials :squinting_face_with_tongue:).

%3CLINGO-SUB%20id%3D%22lingo-sub-2353700%22%20slang%3D%22en-US%22%3EUsing%20Okta%20with%20Static%20Web%20Apps%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2353700%22%20slang%3D%22en-US%22%3E%3CP%3EOne%20of%20my%20favorite%20features%20of%20(the%20now%20General%20Available)%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fstatic-web-apps%2F%3FWT.mc_id%3Djavascript-28109-aapowell%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EAzure%20Static%20Web%20Apps%20(SWA)%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%20that%20in%20the%20Standard%20Tier%20you%20can%20now%20provide%20a%20custom%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fstatic-web-apps%2Fauthentication-custom%3Ftabs%3Daad%26amp%3BWT.mc_id%3Djavascript-28109-aapowell%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EOpenID%20Connect%20(OIDC)%20provider%3C%2FA%3E.%20This%20gives%20you%20a%20lot%20more%20control%20over%20who%20can%20and%20can%E2%80%99t%20access%20your%20app.%3C%2FP%3E%0A%3CP%3EIn%20this%20post%2C%20I%20want%20to%20look%20at%20how%20we%20can%20use%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fwww.okta.com%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EOkta%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%20an%20OIDC%20provider%20for%20Static%20Web%20Apps.%3C%2FP%3E%0A%3CP%3EFor%20this%2C%20you%E2%80%99ll%20need%20an%20Okta%20account%2C%20so%20if%20you%20don%E2%80%99t%20already%20have%20one%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdeveloper.okta.com%2Fsignup%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ego%20sign%20up%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%20maybe%20have%20a%20read%20of%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdeveloper.okta.com%2Fdocs%2Fguides%2Fquickstart%2Fwebsite%2Fcreate-org%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Etheir%20docs%3C%2FA%3E%2C%20just%20so%20you%E2%80%99re%20across%20everything.%3C%2FP%3E%0A%3CH2%20id%3D%22creating-a-static-web-app%22%20id%3D%22toc-hId--466990696%22%20id%3D%22toc-hId--466990659%22%3ECreating%20a%20Static%20Web%20App%3C%2FH2%3E%0A%3CP%3E%3CEM%3EFor%20this%20demo%2C%20we%E2%80%99ll%20use%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Faaronpowell%2Faswa-react-template%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EReact%20template%3C%2FA%3E%2C%20but%20what%20we%E2%80%99re%20covering%20isn%E2%80%99t%20specific%20to%20React%2C%20it%E2%80%99ll%20be%20applicable%20anywhere.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3EOnce%20you%E2%80%99ve%20created%20your%20app%2C%20we%E2%80%99re%20going%20to%20need%20to%20setup%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fstatic-web-apps%2Fconfiguration%3FWT.mc_id%3Djavascript-28109-aapowell%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Econfiguration%20file%3C%2FA%3E%2C%20so%20add%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Estaticwebapp.config.json%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20the%20repo%20root.%3C%2FP%3E%0A%3CP%3EThis%20config%20file%20is%20used%20for%20controlling%20a%20lot%20of%20things%20within%20our%20SWA%2C%20but%20the%20most%20important%20part%20for%20us%20is%20going%20to%20be%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eauth%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Esection.%20Let%E2%80%99s%20flesh%20out%20the%20skeleton%20for%20it%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%7B%0A%20%20%20%20%22auth%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22identityProviders%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22customOpenIdConnectProviders%22%3A%20%7B%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EGreat!%20Now%20it%E2%80%99s%20time%20to%20setup%20Okta.%3C%2FP%3E%0A%3CH2%20id%3D%22creating-an-okta-application%22%20id%3D%22toc-hId-2020522137%22%20id%3D%22toc-hId-2020522174%22%3ECreating%20an%20Okta%20application%3C%2FH2%3E%0A%3CP%3ELog%20into%20the%20Okta%20dashboard%20and%20navigate%20through%20to%20the%20Applications%20section%20of%20the%20portal%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22001.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F280692i308D9EC659987760%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22001.png%22%20alt%3D%22001.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EFrom%20here%2C%20we%E2%80%99re%20going%20to%20select%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ECreate%20App%20Integration%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%20select%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CEM%3EOIDC%20-%20OpenID%20Connect%3C%2FEM%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efor%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESign-on%20method%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CEM%3EWeb%20Application%3C%2FEM%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eas%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EApplication%20type%3C%2FSTRONG%3E.%20You%20might%20be%20tempted%20to%20select%20the%20SPA%20option%2C%20given%20that%20we%E2%80%99re%20creating%20a%20JavaScript%20web%20application%2C%20but%20the%20reason%20we%20don%E2%80%99t%20use%20that%20is%20that%20SWA%E2%80%99s%20auth%20isn%E2%80%99t%20handled%20by%20your%20application%20itself%2C%20it%E2%80%99s%20handled%20by%20the%20underlying%20Azure%20service%2C%20which%20is%20a%20%E2%80%9Cweb%20application%E2%80%9D%2C%20that%20then%20exposes%20the%20information%20out%20that%20you%20need.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22002.png%22%20style%3D%22width%3A%20925px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F280693i8114543F4B026371%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22002.png%22%20alt%3D%22002.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH2%20id%3D%22configure-your-okta-application%22%20id%3D%22toc-hId-213067674%22%20id%3D%22toc-hId-213067711%22%3EConfigure%20your%20Okta%20application%3C%2FH2%3E%0A%3CP%3EWith%20your%20application%20created%2C%20it%E2%80%99s%20time%20to%20configure%20it.%20Give%20it%20a%20name%2C%20something%20that%E2%80%99ll%20make%20sense%20when%20you%20see%20it%20in%20the%20list%20of%20Okta%20applications%2C%20a%20logo%20if%20you%20desire%2C%20but%20leave%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EGrant%20type%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Einformation%20alone%2C%20the%20defaults%20are%20configured%20for%20us%20just%20fine.%3C%2FP%3E%0A%3CP%3EWe%20are%20going%20to%20need%20to%20provide%20the%20application%20with%20some%20redirect%20options%20for%20login%2Flogout%2C%20so%20that%20SWA%20will%20know%20you%E2%80%99ve%20logged%20in%20and%20can%20unpack%20the%20basic%20user%20information.%3C%2FP%3E%0A%3CP%3EFor%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESign-in%20redirect%20URIs%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eyou%20will%20need%20to%20add%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Ehttps%3A%2F%2F%3CHOSTNAME%3E%2F.auth%2Flogin%2Fokta%2Fcallback%3C%2FHOSTNAME%3E%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%20for%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESign-out%20redirect%20URIs%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eadd%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Ehttps%3A%2F%2F%3CHOSTNAME%3E%2F.auth%2Flogout%2Fokta%2Fcallback%3C%2FHOSTNAME%3E%3C%2FCODE%3E.%20If%20you%20haven%E2%80%99t%20yet%20deployed%20to%20Azure%2C%20don%E2%80%99t%20worry%20about%20this%20step%20yet%2C%20we%E2%80%99ll%20do%20it%20once%20the%20SWA%20is%20created.%3C%2FP%3E%0A%3CP%3E%3CEM%3EQuick%20note%20-%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eokta%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalue%20here%20is%20going%20to%20be%20how%20we%20name%20the%20provider%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Estaticwebapp.config.json%3C%2FCODE%3E%2C%20so%20it%20can%20be%20anything%20you%20want%2C%20I%20just%20like%20to%20use%20the%20provider%20name%20so%20the%20config%20is%20easy%20to%20read.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3EClick%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESave%3C%2FSTRONG%3E%2C%20and%20it%E2%80%99s%20time%20to%20finish%20off%20our%20SWA%20config%20file.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22003.png%22%20style%3D%22width%3A%20581px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F280694i6C692CBEC355E221%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22003.png%22%20alt%3D%22003.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH2%20id%3D%22completing-our-settings%22%20id%3D%22toc-hId--1594386789%22%20id%3D%22toc-hId--1594386752%22%3ECompleting%20our%20settings%3C%2FH2%3E%0A%3CP%3EWith%20our%20Okta%20application%20setup%2C%20it%E2%80%99s%20time%20to%20complete%20our%20config%20file%20so%20it%20can%20use%20it.%20We%E2%80%99ll%20add%20a%20new%20configuration%20under%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EcustomOpenIdConnectProviders%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efor%20Okta%20and%20it%E2%80%99ll%20contain%20two%20core%20pieces%20of%20information%2C%20the%20information%20on%20how%20to%20register%20the%20OIDC%20provider%20and%20some%20login%20information%20on%20how%20to%20talk%20to%20the%20provider.%3C%2FP%3E%0A%3CP%3EInside%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eregistration%3C%2FCODE%3E%2C%20we%E2%80%99ll%20add%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EclientIdSettingName%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efield%2C%20which%20will%20point%20to%20an%20entry%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fstatic-web-apps%2Fapplication-settings%3FWT.mc_id%3Djavascript-28109-aapowell%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Eapp%20settings%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ethat%20the%20SWA%20has.%20Next%2C%20we%E2%80%99ll%20need%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EclientCredential%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%20that%20has%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EclientSecretSettingName%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ethat%20is%20the%20entry%20for%20the%20OIDC%20client%20secret.%20Lastly%2C%20we%E2%80%99ll%20provide%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EopenIdConnectConfiguration%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ewith%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EwellKnownOpenIdConfiguration%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eendpoint%20that%20is%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Ehttps%3A%2F%2F%3CYOUR_OKTA_DOMAIN%3E%2F.well-known%2F%2Fopenid-configuration%3C%2FYOUR_OKTA_DOMAIN%3E%3C%2FCODE%3E.%3C%2FP%3E%0A%3CP%3EThe%20config%20should%20now%20look%20like%20this%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%7B%0A%20%20%20%20%22auth%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22identityProviders%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22customOpenIdConnectProviders%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22okta%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22registration%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22clientIdSettingName%22%3A%20%22OKTA_ID%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22clientCredential%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22clientSecretSettingName%22%3A%20%22OKTA_SECRET%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22openIdConnectConfiguration%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22wellKnownOpenIdConfiguration%22%3A%20%22https%3A%2F%2Fdev-920852.okta.com%2F.well-known%2Fopenid-configuration%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%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%3CEM%3EI%20use%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EOKTA_ID%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EOKTA_SECRET%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eas%20the%20names%20of%20the%20items%20I%E2%80%99ll%20be%20putting%20into%20app%20settings.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3EAll%20this%20information%20will%20tell%20SWA%20how%20to%20issue%20a%20request%20against%20the%20right%20application%20in%20Okta%2C%20but%20we%20still%20need%20to%20tell%20it%20how%20to%20make%20the%20request%20and%20handle%20the%20response.%20That%E2%80%99s%20what%20we%20use%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Elogin%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Econfig%20for.%20With%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Elogin%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Econfig%2C%20we%20provide%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EnameClaimType%3C%2FCODE%3E%2C%20which%20is%20a%20fully-qualified%20path%20to%20the%20claim%20that%20we%20want%20SWA%20to%20use%20as%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fstatic-web-apps%2Fuser-information%3Ftabs%3Djavascript%26amp%3BWT.mc_id%3Djavascript-28109-aapowell%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%3CCODE%3EuserDetails%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efield%20of%20the%20user%20info%3C%2FA%3E.%20Generally%20speaking%2C%20you%E2%80%99ll%20want%20this%20to%20be%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%3CA%20class%3D%22vglnk%22%20href%3D%22http%3A%2F%2Fschemas.xmlsoap.org%2Fws%2F2005%2F05%2Fidentity%2Fclaims%2Fname%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22_blank%22%3E%3CSPAN%3Ehttp%3C%2FSPAN%3E%3CSPAN%3E%3A%2F%2F%3C%2FSPAN%3E%3CSPAN%3Eschemas%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3Exmlsoap%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3Eorg%3C%2FSPAN%3E%3CSPAN%3E%2F%3C%2FSPAN%3E%3CSPAN%3Ews%3C%2FSPAN%3E%3CSPAN%3E%2F%3C%2FSPAN%3E%3CSPAN%3E2005%3C%2FSPAN%3E%3CSPAN%3E%2F%3C%2FSPAN%3E%3CSPAN%3E05%3C%2FSPAN%3E%3CSPAN%3E%2F%3C%2FSPAN%3E%3CSPAN%3Eidentity%3C%2FSPAN%3E%3CSPAN%3E%2F%3C%2FSPAN%3E%3CSPAN%3Eclaims%3C%2FSPAN%3E%3CSPAN%3E%2F%3C%2FSPAN%3E%3CSPAN%3Ename%3C%2FSPAN%3E%3C%2FA%3E%3C%2FCODE%3E%2C%20but%20if%20there%E2%80%99s%20a%20custom%20field%20in%20your%20response%20claims%20you%20want%20to%20use%2C%20make%20sure%20you%20provide%20that.%20The%20other%20bit%20of%20config%20we%20need%20here%20is%20what%20scopes%20to%20request%20from%20Okta.%20For%20SWA%2C%20you%20only%20need%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eopenid%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eprofile%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eas%20the%20scopes%2C%20unless%20you%E2%80%99re%20wanting%20to%20use%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EnameClaimType%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eother%20than%20standard.%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20finish%20off%20our%20SWA%20config%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%7B%0A%20%20%20%20%22auth%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22identityProviders%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22customOpenIdConnectProviders%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22okta%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22registration%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22clientIdSettingName%22%3A%20%22OKTA_ID%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22clientCredential%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22clientSecretSettingName%22%3A%20%22OKTA_SECRET%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22openIdConnectConfiguration%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22wellKnownOpenIdConfiguration%22%3A%20%22https%3A%2F%2Fdev-920852.okta.com%2F.well-known%2Fopenid-configuration%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22login%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22nameClaimType%22%3A%20%22http%3A%2F%2Fschemas.xmlsoap.org%2Fws%2F2005%2F05%2Fidentity%2Fclaims%2Fname%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22scopes%22%3A%20%5B%22openid%22%2C%20%22profile%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWith%20the%20config%20ready%20you%20can%20create%20the%20SWA%20in%20Azure%20and%20kick%20off%20a%20deployment%20(don%E2%80%99t%20forget%20to%20update%20the%20Okta%20app%20with%20the%20login%2Flogout%20callbacks).%20When%20the%20resource%20is%20created%20in%20Azure%2C%20copy%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EClient%20ID%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EClient%20secret%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efrom%20Okta%20and%20create%20app%20settings%20in%20Azure%20using%20the%20names%20in%20your%20config%20and%20the%20values%20from%20Okta.%3C%2FP%3E%0A%3CH2%20id%3D%22using-the-provider%22%20id%3D%22toc-hId-893126044%22%20id%3D%22toc-hId-893126081%22%3EUsing%20the%20provider%3C%2FH2%3E%0A%3CP%3EOnce%20the%20provider%20is%20registered%20in%20the%20config%20file%2C%20it%20is%20usable%20just%20like%20the%20other%20providers%20SWA%20offers%2C%20with%20the%20login%20being%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%2F.auth%2Flogin%2F%3CPROVIDER_NAME%3E%3C%2FPROVIDER_NAME%3E%3C%2FCODE%3E%2C%20which%20in%20this%20case%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eprovider_name%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eokta%3C%2FCODE%3E.%20The%20user%20information%20will%20then%20be%20exposed%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fwww.aaron-powell.com%2Fposts%2F2021-05-13-using-okta-with-static-web-apps%2F(https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fstatic-web-apps%2Fuser-information%3Ftabs%3Djavascript%26amp%3BWT.mc_id%3Djavascript-28109-aapowell)%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Eas%20standard%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20both%20the%20web%20and%20API%20components.%3C%2FP%3E%0A%3CP%3EIf%20you%E2%80%99re%20building%20a%20React%20application%2C%20check%20out%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F%40aaronpowell%2Freact-static-web-apps-auth%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Emy%20React%20auth%20helper%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%20for%20the%20API%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F%40aaronpowell%2Fstatic-web-apps-api-auth%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ethere%20is%20a%20companion%3C%2FA%3E.%3C%2FP%3E%0A%3CH2%20id%3D%22conclusion%22%20id%3D%22toc-hId--914328419%22%20id%3D%22toc-hId--914328382%22%3EConclusion%3C%2FH2%3E%0A%3CP%3EI%20really%20like%20that%20with%20the%20GA%20of%20Static%20Web%20Apps%20we%20are%20now%20able%20to%20use%20custom%20OIDC%20providers%20with%20the%20platform.%20This%20makes%20it%20a%20lot%20easier%20to%20have%20controlled%20user%20access%20and%20integration%20with%20a%20more%20complex%20auth%20story%20when%20needed.%20Setting%20this%20up%20with%20Okta%20only%20takes%20a%20few%20lines%20of%20config.%3C%2FP%3E%0A%3CP%3EYou%20can%20check%20out%20a%20full%20code%20sample%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Faaronpowell%2Fswa-custom-auth-okta%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Eon%20my%20GitHub%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%20a%20live%20demo%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fblue-bay-0eac9b910.azurestaticapps.net%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E(but%20I%E2%80%99m%20not%20giving%20you%20my%20Okta%20credentials%20%3Asquinting_face_with_tongue%3A).%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2353700%22%20slang%3D%22en-US%22%3E%3CDIV%3E%0A%3CDIV%3E%3CSPAN%3EWith%26nbsp%3BAzure%26nbsp%3BStatic%26nbsp%3BWeb%26nbsp%3BApps%26nbsp%3Bsupporting%26nbsp%3Bcustom%26nbsp%3Bauthentication%2C%26nbsp%3Blet's%26nbsp%3Blook%26nbsp%3Bat%26nbsp%3Bhow%26nbsp%3Bwe%26nbsp%3Bcan%26nbsp%3Buse%26nbsp%3BOkta%26nbsp%3Bas%26nbsp%3Ba%26nbsp%3Bprovider.%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3C%2FDIV%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2353700%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWeb%20Apps%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎May 13 2021 10:12 PM
Updated by: