Giter VIP home page Giter VIP logo

oktadev / schematics Goto Github PK

View Code? Open in Web Editor NEW
71.0 6.0 29.0 2.43 MB

Schematics for adding Okta and Auth0 Auth to your projects

Home Page: https://auth0.com/blog/quick-javascript-authentication/

License: Apache License 2.0

TypeScript 75.14% HTML 2.41% Shell 6.25% JavaScript 12.18% Vue 3.61% Pug 0.41%
authentication okta angular schematics oauth2 oidc react vue ionic expressjs react-native typescript auth0 javascript quickstart

schematics's Introduction

OktaDev Schematics

NPM version Build Status Known Vulnerabilities

Fast and easy installation of Okta and Auth0's OIDC SDKs

This project is a Schematics implementation that allows you to easily integrate Okta and Auth0 into your Angular, React, Vue, Ionic, React Native, and Express projects.

This library currently supports:

Prerequisites: Node.js.

Use the links below to see how to create an app and integrate authentication using OktaDev Schematics.

To learn more about this project, see the following topics:

Angular

First, create an empty project with Angular CLI. You must add Angular routing for this schematic to work.

npm i -g @angular/cli
ng new secure-angular --routing
cd secure-angular

Then, integrate your Angular app with Okta or Auth0.

Okta for Angular

  1. Install the Okta CLI.
  2. Run okta register to create an account, followed by okta apps create.
  3. Choose Single Page App and use http://localhost:4200/callback for the Redirect URI.

In your secure-angular project, add @oktadev/schematics:

ng add @oktadev/schematics

Use the values that the Okta CLI provides for the issuer and client ID when prompted.

Run npm start, open http://localhost:4200 in your browser, and sign in. 🥳

See the Okta Angular SDK for more information.

You can also use the Okta Admin Console:

  • Log in to your Okta instance (or create an account if you don't have one). Go to Applications > Create App Integration > OIDC.
  • Choose Single-Page Application as the application type and click Next.
  • Add http://localhost:4200/callback as a Sign-in redirect URI and http://localhost:4200 as a Sign-out redirect URI.
  • Specify http://localhost:4200 as a Trusted Origin and click Save.

Auth0 for Angular

  1. Install the Auth0 CLI.
  2. Run auth0 login to register your account, followed by auth0 apps create.
  3. Specify a name and description of your choosing.
  4. Select Single Page Web Application and use http://localhost:4200/home for the Callback URLs.
  5. Use http://localhost:4200 for the rest of the URLs.

In your secure-angular project, add @oktadev/schematics with the --auth0 flag:

ng add @oktadev/schematics --auth0

Use the values that the Auth0 CLI provides for the issuer and client ID when prompted.

Run npm start, open http://localhost:4200 in your browser, and sign in. 🥳

See the Auth0 Angular SDK for more information.

You can also use the Auth0 Console:

  • Log in to Auth0 or create an account if you don't have one. Go to Applications > Create Application.
  • Choose Single Page Web Applications as the application type and click Create.
  • Select the Settings tab.
  • Add http://localhost:4200/home as an Allowed Callback URL and http://localhost:4200 as a Logout URL.
  • Specify http://localhost:4200 as an Allowed Origin and click Save Changes at the bottom.

React

Create a new project with Create React App.

npx create-react-app secure-react
cd secure-react

If you'd like to use TypeScript, add the --template typescript flag.

npx create-react-app secure-react --template typescript
cd secure-react

Then, integrate your React app with Okta or Auth0.

Okta for React

  1. Install the Okta CLI.
  2. Run okta register to create an account, followed by okta apps create.
  3. Choose Single Page App and use http://localhost:3000/callback for the Redirect URI.

Install the Schematics CLI globally.

npm install -g @angular-devkit/schematics-cli

Then install and run the add-auth schematic in your secure-react project.

npm i -D @oktadev/schematics
schematics @oktadev/schematics:add-auth

Use the values that the Okta CLI provides for the issuer and client ID when prompted.

Run npm start, open http://localhost:3000 in your browser, and sign in. 🎉

See the Okta React SDK for more information.

You can also use the Okta Admin Console:

  • Log in to your Okta instance (or create an account if you don't have one). Go to Applications > Create App Integration > OIDC.
  • Choose Single-Page Application as the application type and click Next.
  • Add http://localhost:3000/callback as a Sign-in redirect URI and http://localhost:3000 as a Sign-out redirect URI.
  • Add http://localhost:3000 as a Trusted Origin and click Save.

Auth0 for React

  1. Install the Auth0 CLI.
  2. Run auth0 login to register your account, followed by auth0 apps create.
  3. Specify a name and description of your choosing.
  4. Select Single Page Web Application and use http://localhost:3000 for the Callback URL.
  5. Use http://localhost:3000 for the rest of the URLs.

Install the Schematics CLI globally.

npm install -g @angular-devkit/schematics-cli

Then install and run the add-auth schematic in your secure-react project with the --auth0 flag:

npm i -D @oktadev/schematics
schematics @oktadev/schematics:add-auth --auth0

Use the values that the Auth0 CLI provides for the issuer and client ID when prompted.

Run npm start, open http://localhost:3000 in your browser, and sign in. 🎉

See the Auth0 React SDK for more information.

You can also use the Auth0 Console:

  • Log in to Auth0 or create an account if you don't have one. Go to Applications > Create Application.
  • Choose Single Page Web Applications as the application type and click Create.
  • Select the Settings tab.
  • Add http://localhost:3000 as an Allowed Callback URL and http://localhost:3000 as a Logout URL.
  • Specify http://localhost:3000 as an Allowed Origin and click Save Changes at the bottom.

Vue

Create a new project with Vue CLI. You must add routing for this schematic to work. If you specify TypeScript, a src/router/index.ts will be used.

npm i -g @vue/cli
vue create secure-vue
cd secure-vue

Then, integrate your Vue app with Okta or Auth0.

Okta for Vue

  1. Install the Okta CLI.
  2. Run okta register to create an account, followed by okta apps create.
  3. Choose Single Page App and use http://localhost:8080/callback for the Redirect URI.

Install the Schematics CLI globally.

npm install -g @angular-devkit/schematics-cli

Then install and run the add-auth schematic in your secure-vue project.

npm i -D @oktadev/schematics
schematics @oktadev/schematics:add-auth

Use the values that the Okta CLI provides for the issuer and client ID when prompted.

Run npm run serve, open http://localhost:8080 in your browser, and sign in. 💥

See the Okta Vue SDK for more information.

You can also use the Okta Admin Console:

  • Log in to your Okta instance (or create an account if you don't have one). Go to Applications > Create App Integration > OIDC.
  • Choose Single-Page Application as the application type and click Next.
  • Add http://localhost:8080/callback as a Sign-in redirect URI and http://localhost:8080 as a Sign-out redirect URI.
  • Add http://localhost:8080 as a Trusted Origin and click Save.

Auth0 for Vue

  1. Install the Auth0 CLI.
  2. Run auth0 login to register your account, followed by auth0 apps create.
  3. Specify a name and description of your choosing.
  4. Select Single Page Web Application and use http://localhost:8080 for the Callback URL.
  5. Use http://localhost:8080 for the rest of the URLs.

Install the Schematics CLI globally.

npm install -g @angular-devkit/schematics-cli

Then install and run the add-auth schematic in your secure-react project with the --auth0 flag:

npm i -D @oktadev/schematics
schematics @oktadev/schematics:add-auth --auth0

Use the values that the Auth0 CLI provides for the issuer and client ID when prompted.

Run npm run serve, open http://localhost:8080 in your browser, and sign in. 💥

See the Auth0 Vue SDK for more information.

You can also use the Auth0 Console:

  • Log in to Auth0 or create an account if you don't have one. Go to Applications > Create Application.
  • Choose Single Page Web Applications as the application type and click Create.
  • Select the Settings tab.
  • Add http://localhost:8080 as an Allowed Callback URL and http://localhost:8080 as a Logout URL.
  • Specify http://localhost:8080 as an Allowed Origin and click Save Changes at the bottom.

Ionic

Create a new Ionic + Angular project with Ionic CLI. You must use the tabs layout for everything to work correctly.

npm install -g @ionic/cli
ionic start secure-ionic tabs --type=angular --no-interactive 
cd secure-ionic

Then, integrate your Ionic app with Okta or Auth0.

Okta for Ionic

  1. Install the Okta CLI.
  2. Run okta register to create an account, followed by okta apps create.
  3. Choose Native and use [com.okta.dev-133337:/callback,http://localhost:8100/callback,https://localhost] for the Login redirect URIs (where dev-133337.okta.com is your Okta domain).
  4. Use [com.okta.dev-133337:/logout,http://localhost:8100/logout] for the Logout redirect URIs.

In your secure-ionic project, add @oktadev/schematics:

ng add @oktadev/schematics

Use the values that the Okta CLI provides for the issuer and client ID when prompted.

Start your app and authenticate with Okta. 🎊

ionic serve

You can also use the Okta Admin Console:

Log in to your Okta instance (or sign up if you don't have an account).

From the Applications page, choose Create App Integration > OIDC. Select Native Application.

Give your app a memorable name, and configure it as follows:

  • Sign-in redirect URIs:
    • http://localhost:8100/callback
    • com.okta.dev-133337:/callback (where dev-133337.okta.com is your Okta domain)
    • https://localhost
  • Sign-out redirect URIs:
    • http://localhost:8100/logout
    • com.okta.dev-133337:/logout
  • Trusted Origins:
    • http://localhost:8100
  • Click Save

Auth0 for Ionic

  1. Install the Auth0 CLI.
  2. Run auth0 login to register your account, followed by auth0 apps create.
  3. Specify a name and description of your choosing.
  4. Select Native and use dev.localhost.ionic:/callback,http://localhost:8100/callback for the Callback URLs.
  5. Use dev.localhost.ionic:/logout,http://localhost:8100/logout for the Logout URLs.
  6. Run auth0 apps open and add http://localhost:8100,http://localhost to Allowed Origins (CORS). Scroll down and Save Changes.

In your secure-ionic project, add @oktadev/schematics with the --auth0 flag:

ng add @oktadev/schematics --auth0

Use the values that the Auth0 CLI provides for the issuer and client ID when prompted.

Start your app and authenticate with Auth0. 🎊

ionic serve

You can also use the Auth0 Console:

  • Log in to Auth0 or create an account if you don't have one. Go to Applications > Create Application.
  • Choose Native as the application type and click Create.
  • Select the Settings tab.
  • Add dev.localhost.ionic:/callback,http://localhost:8100/callback for Allowed Callback URLs and dev.localhost.ionic:/logout,http://localhost:8100/logout for the Logout URLs.
  • Add http://localhost:8100,https://localhost to Allowed Origins (CORS). Scroll down and Save Changes.

iOS

Build and add Capacitor for iOS with the following commands:

ionic build
npm i @capacitor/ios
npx cap add ios

Add your custom scheme to ios/App/App/Info.plist:

<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLName</key>
    <string>com.getcapacitor.capacitor</string>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>dev.localhost.ionic</string>
      <string>com.okta.dev-133337</string>
    </array>
  </dict>
</array>

Then, run your project using the Capacitor CLI:

npx cap run ios

You can also open your project in Xcode and configure code signing.

npx cap open ios

Then run your app from Xcode.

Android

Build and add Capacitor for Android with the following commands:

ionic build
npm i @capacitor/android
npx cap add android

Add your reverse domain name as the android:scheme in android/app/src/main/AndroidManifest.xml by adding another <intent-filter> above the existing one in the <activity> element.

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="com.okta.dev-133337" /> <!-- use dev.localhost.ionic for Auth0 -->
</intent-filter>

Then, run your project using the Capacitor CLI:

npx cap run android

You can also open your project in Android Studio and run your app.

npx cap open android

See Ionic's iOS and Android Development docs for more information.

React Native

Create a new React Native project with the React Native CLI.

npx react-native init SecureApp

Then, integrate your React Native app with Okta or Auth0.

Okta for React Native

  1. Install the Okta CLI.
  2. Run okta register to create an account, followed by okta apps create.
  3. Choose Native and accept the default Redirect URI of com.okta.dev-133337:/callback (where dev-133337.okta.com is your Okta domain).
  4. Use com.okta.dev-133337:/logout for the Post Logout Redirect URI.

Install the Schematics CLI globally.

npm install -g @angular-devkit/schematics-cli

Install and run the add-auth schematic in your SecureApp project.

cd SecureApp
npm i -D @oktadev/schematics
schematics @oktadev/schematics:add-auth --issuer=$issuer --client-id=$clientId

You can also use the Okta Admin Console:

  • Log in to your Okta instance (or create an account if you don't have one). Go to Applications > Create App Integration > OIDC.
  • Choose Native as the application type and click Next.
  • Add com.okta.dev-133337:/callback as a Sign-in redirect URI and com.okta.dev-133337:/callback as a Sign-out redirect URI (where dev-133337.okta.com is your Okta domain).

Auth0 for React Native

  1. Install the Auth0 CLI.

  2. Run auth0 login to register your account, followed by auth0 apps create.

  3. Specify a name and description of your choosing.

  4. Select Native and use the following for your Callback and Logout URLs:

    org.reactjs.native.example.<yourappname>.auth0://<your-auth0-domain>/ios/org.reactjs.native.example.<yourappname>/callback,com.<yourappname>.auth0://<your-auth0-domain>/android/com.<yourappname>/callback
    

For example:

org.reactjs.native.example.secureauth0.auth0://dev-06bzs1cu.us.auth0.com/ios/org.reactjs.native.example.secureauth0/callback, com.secureauth0.auth0://dev-06bzs1cu.us.auth0.com/android/com.secureauth0/callback

Install the Schematics CLI globally.

npm install -g @angular-devkit/schematics-cli

Install and run the add-auth schematic in your SecureApp project with the --auth0 flag.

cd SecureApp
npm i -D @oktadev/schematics
schematics @oktadev/schematics:add-auth --issuer=$issuer --client-id=$clientId --auth0

You can also use the Auth0 Console:

  • Log in to Auth0 or create an account if you don't have one. Go to Applications > Create Application.

  • Choose Native as the application type and click Create.

  • Select the Settings tab.

  • Add the following for Allowed Callback and Logout URLs:

     org.reactjs.native.example.<yourappname>.auth0://<your-auth0-domain>/ios/org.reactjs.native.example.<yourappname>/callback,com.<yourappname>.auth0://<your-auth0-domain>/android/com.<yourappname>/callback
    

For example:

org.reactjs.native.example.secureauth0.auth0://dev-06bzs1cu.us.auth0.com/ios/org.reactjs.native.example.secureauth0/callback, com.secureauth0.auth0://dev-06bzs1cu.us.auth0.com/android/com.secureauth0/callback

iOS

Run npx pod-install.

Start your app and authenticate with Okta. 🎉

npm run ios

NOTE: If you have issues with compiling, you may have to disable Flipper in ios/Podfile. Then run npx pod-install again.

Android

One change is made to Android build files. In android/app/build.gradle, a manifestPlaceholders is added in android > defaultConfig.

Since this modification is done for you, you can simply start your app and authenticate with Okta. 🎊

npm run android

For more information, see the Okta React Native SDK and the Auth0 React Native SDK.

Express

Create a new project with express-generator and pug.

mkdir express-app
cd express-app
npx express-generator --view=pug

Then, integrate your Express app with Okta or Auth0.

Okta for Express

  1. Install the Okta CLI.
  2. Run okta register to create an account, followed by okta apps create.
  3. Choose Web > Other and use http://localhost:3000/callback for the Redirect URI.
  4. Accept the default Post Logout Redirect URI (http://localhost:3000/).

Install the Schematics CLI globally.

npm install -g @angular-devkit/schematics-cli

Then install and run the add-auth schematic in your express-app project.

The Okta CLI will create an .okta.env file in the current directory. It will have the values you need. After you use them in the command below, you can delete this file.

npm i -D @oktadev/schematics
schematics @oktadev/schematics:add-auth --issuer=$issuer \
  --client-id=$clientId --client-secret=$clientSecret

🚨 This process will create an .env file will be generated with your credentials. Make sure to add *.env to .gitignore and don't check it into source control!

Start your app and authenticate with Okta at http://localhost:3000. 🎊

npm start

See the Okta OIDC Middleware SDK for more information.

You can also create your app using the Okta Admin Console:

  • Log into the Okta Developer Dashboard (or create an account if you don't have one), click Applications then Create App Integration > OIDC.
  • Choose Web as the application type and click Next.
  • Add a Sign-in redirect URI of http://localhost:3000/callback.
  • Add a Sign-out redirect URI of http://localhost:3000.
  • Click Save.

Auth0 for Express

  1. Install the Auth0 CLI.
  2. Run auth0 login to register your account, followed by auth0 apps create.
  3. Specify a name and description of your choosing.
  4. Select Regular Web Application and use http://localhost:3000/callback for the Callback URL.
  5. Use http://localhost:3000 for the Logout URL.

Install the Schematics CLI globally.

npm install -g @angular-devkit/schematics-cli

Then install and run the add-auth schematic in your express-app project with the --auth0 flag.

Use the values that the Auth0 CLI provides for the issuer and client ID. You may have to use auth0 apps open to get the client secret for your app.

npm i -D @oktadev/schematics
schematics @oktadev/schematics:add-auth --issuer=$issuer \
  --client-id=$clientId --client-secret=$clientSecret --auth0

🚨 This process will create an .env file with your credentials. Make sure to add *.env to .gitignore and don't check it into source control!

Start your app and authenticate with Auth0 at http://localhost:3000. 🎊

npm start

See the Auth0 Express OpenID Connect SDK for more information.

You can also use the Auth0 Console:

  • Log in to Auth0 or create an account if you don't have one. Go to Applications > Create Application.
  • Choose Regular Web Application as the application type and click Create.
  • Select the Settings tab.
  • Add http://localhost:3000/callback as an Allowed Callback URL and http://localhost:3000 as a Logout URL.
  • Click Save Changes at the bottom.

Testing

This project supports unit tests and integration tests.

npm test will run the unit tests, using Jasmine as a runner and test framework.

./test-app.sh angular will create an Angular project with Angular CLI, install this project, and make sure all the project's tests pass. Other options include react, react-ts, vue, vue-ts, ionic, ionic, react-native, and express. You can also add -auth0 to any of these options.

./test-all.sh will test all the options for both Okta and Auth0: Angular, React, React with TypeScript, Vue, Vue with TypeScript, Ionic with Capacitor, React Native, and Express.

Publishing

To publish, simply do:

npm publish

That's it!

Contributing

If you'd like to modify this library, and contribute your changes, you can start by forking it to your own GitHub repository. Then, clone it to your hard drive.

git clone [email protected]:<your username>/schematics.git
cd schematics

Create a new branch for your changes:

git checkout -b my-awesome-branch

Make the changes you want to make and add tests where appropriate. Create a new project with whatever framework you're using, then run the following command inside it to use your modified project.

npm link /path/to/schematics

You'll need to run npm run build whenever you change anything in the schematics project.

NOTE: You can also use npm pack in your schematics project, then npm install /path/to/artifact.tar.gz in your test project.

Tutorials

Check out the following blog posts to see OktaDev Schematics in action.

Links

This project uses the following open source libraries from Okta:

And these from Auth0:

For Ionic, it uses Ionic AppAuth.

Help

Please post any questions as issues or ask them on the Okta Developer Forums or Auth0 Community Forums.

License

Apache 2.0, see LICENSE.

schematics's People

Contributors

danielruf avatar dependabot-preview[bot] avatar dependabot[bot] avatar github-actions[bot] avatar mraible avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

schematics's Issues

Okta logout Issue - User can able to login the app without giving credentials -IOS

I logged in my ionic application with my okta credentials. After successful login, I logged out. Now, i am trying to login. app logged it automatically without asking for credentials and landing me in home page. as of now, i am clearing history and website data in safari settings. Then only its asking for credentials. We are using shard device and have to allow multiple users to login in same device .

await this.auth.signOut();

Ionic:

Ionic CLI : 6.16.1
Ionic Framework : @ionic/angular 5.6.9
@angular-devkit/build-angular : 0.901.15
@angular-devkit/schematics : 11.2.9
@angular/cli : 9.1.15
@ionic/angular-toolkit : 2.3.3

Cordova:

Cordova CLI : 10.0.0
Cordova Platforms : ios 5.1.1
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1

Utility:
cordova-res : 0.15.3

System:
ios-deploy : 1.11.4
ios-sim : 8.0.2
NodeJS : v14.17.0
npm : 6.14.13
OS : macOS Big Sur
Xcode : Xcode 12.5.1 Build version 12E507

Add support for alternative Angular styles

Options are CSS, SCSS, Sass, Less, and Stylus. Only CSS is currently supported. One way to determine this might be to parse the schematics value from projects[0] in angular.json.

"schematics": {
  "@schematics/angular:component": {
    "style": "scss"
  }
},

devDependency or dependency?

In the docs you sometimes use npm i @oktadev/schematics and sometimes npm i -D @oktadev/schematics`.

Is this a devDepndency in general or does it depend on the setup? Because this is not clear and currently @oktadev/schematics uses a dependency with vulnerabilities (ini 1.3.5, loaded by schematics-utilities 2.0.2).

See https://snyk.io/vuln/SNYK-JS-INI-1048974

OktaDev Schematics doesn't work with Angular CLI 12

Error:

$ ng add @oktadev/schematics
ℹ Using package manager: npm
✔ Found compatible package version: @oktadev/[email protected].
✔ Package information loaded.

The package @oktadev/[email protected] will be installed and executed.
Would you like to proceed? Yes
✔ Package successfully installed.
? What is your OIDC app's issuer URL? https://dev-9323263.okta.com/oauth2/default
? What is your OIDC app's client ID? 0oambt69c4LNBiJ7u5d6
Schematic input does not validate against the Schema: {"project":"foo","clientId":"0oambt69c4LNBiJ7u5d6"}
Errors:

  Data path "" must have required property 'issuer'.

Posted question to Stack Overflow: https://stackoverflow.com/questions/67185977/angular-12-schematics-throws-error-about-required-properties

Unable to get refresh token when adding 'offline_access'

Hi,

Following your guide https://developer.okta.com/blog/2019/06/20/ionic-4-tutorial-user-authentication-and-registration which is great, I noticed that when I add the 'offline_access' scope (to get the refresh token) in the configuration, the /token gets an error saying that this scope is not supported.

In fact, while implementing Authorization Code flow, you need to specify 'offline_access'' on the /authorize endpoint instead of /token (https://developer.okta.com/docs/guides/refresh-tokens/get-refresh-token/)

My question is : is it possible to specify the offline_access only for the /authorize endpoint instead of both with OktaDev Schematics ?

Thanks in advance,
Bruno.

Capacitor 3 Sign out issue

Login and refresh work fine but on signout I get this error:

E/Capacitor: JavaScript Error: "No Activity found to handle Intent { act=android.intent.action.VIEW dat=undefined?id_token_hint=eyJhbGciOiJSUzI1...&post_logout_redirect_uri=com.local.app://logout&state=XCRqxoqFth pkg=com.android.chrome (has extras) }\"}"}}

I have the intent in AndroidManifest.xml required by capacitor app plugin

<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data android:scheme="@string/custom_url_scheme" />
</intent-filter>

Ionic Capacitor AuthGuard IsAuthenticated False On App Launch

When my app launches my homepage has an AuthGuard that redirects to the login. After the upgrade when my homepage AuthGuard is ran the auth.session.isAuthenticated is always false until the token is loaded from storage. This causes users to redirect to the login screen for about a second, then they get redirected again to the homepage. What is the recommend way to fetch the token from storage before my AuthGuard is ran?

Manual Installation option / Okta sign-in widget CORS issues

Hi,

It seems that this plugin overwrites a lot of files and will actually corrupt a project in a sense if there is already an Okta configuration setup.

I believe this would be useful if rather than forcing the automation of file changes, to simply install all the required plugins needed, and to have documentation that points you in the right direction, as I'm going to have to do this manually by looking at the included files.

This seems like a great starting point for a fresh project, but for me with an existing project and routes/tabs, it will break my application.

Some people have to integrate this manually, so simply providing how to do that can save developers with existing configurations time and effort.

Great plugin, glad to see this exists and provides a clear way to integrate Okta authentication in PWAs.

Issue logging in from mobile App on android devices IONIC + android issue

Important:- Our app is created in IONIC framework (with Cordova) and we have user OIDC for OKTA authentication.

Please note: We are using latest version of IONIC (IONIC 6) and Angular (Angular 12). The authentication works seamless on IOS. Only some of the Android devices have reported this problem.

We have used @oktadev/schematics & OpenID Connect.

The error (information below) is observed only with some Android devices. The same user when used with other Android devices is authenticated successfully and is signed in to the app.
Steps on how the error was found:

Step 1: Install the APP on Android device.
Step 2: Enter the login details
Step 3: The app redirects the user to the OKTA authentication page.
Step 4: When the user enters the correct password, the browser is closed and the user is redirected to the app.
Here, we attached breakpoints in the authentication process to get into the details of why the user is not logged in to the app.
When the authorization request is completed, it is calling the function “completeAuthorizationRequest”, and in this function, an error was observed which is “Handle Not Available”, screenshot below:

Picture2

When we bypassed this error, we were redirected to the OnSignInSuccess method, and the action received was “Sign In Failed”.
So even after the user has successfully logged in on the OKTA authentication page, the action received is still “Sign In Failed”.

Picture1

Key points to note:

  1. After this step, the user has no choice but to kill the APP.

  2. When he kills the app and launch it again, the user inputs the LoginName again.
    As soon as he enters the LoginName, he is redirected to the OKTA page and immediately returned back to the app stating he is authenticated successfully (I believe it’s because the token is set in the storage).

  3. We are unable to create the HAR file because it’s not being generated when we are debugging it through the code.

Firebase Deep link error

Hi,
When using cordova-plugin-firebasex plugin App not login.Getting error below

[FirebaseAnalytics][I-ACS023001] Deep Link does not contain valid required params. URL params: {
code = "";
state = ;
}

"cordova-plugin-firebasex": "^14.1.0",
"@oktadev/schematics": "5.2.2",

Ionic:

Ionic CLI : 6.19.0
Ionic Framework : @ionic/angular 6.1.6
@angular-devkit/build-angular : 13.3.6
@angular-devkit/schematics : 13.3.6
@angular/cli : 13.3.6
@ionic/angular-toolkit : 5.0.3

Cordova:

Cordova CLI : 11.0.0
Cordova Platforms : ios 6.2.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 13 other plugins)

Utility:

cordova-res : 0.15.4
native-run (update available: 1.6.0) : 1.5.0

System:

Android SDK Tools : 26.1.1
ios-deploy : 1.11.4
ios-sim : 8.0.2
NodeJS : v16.14.2
npm : 8.5.0
OS : macOS Monterey
Xcode : Xcode 13.4.1 Build version 13F100

Issue in getting new access token

Hi, I have create a new ionic app with angular using the okta-dev/schematics and i am facing an issue where the user gets logged out automatically as the token expires and call to /token endpoint fails with the following error.

Screen Shot 2020-11-16 at 5 35 17 pm

I have allowded the grant type refresh token in my application created in okta. But what i have found is that the getValidToken() is causing this issue if the token in the local storage has expired. It tries to make a call to /token endpoint for a refreshToken with grant_type as refresh_token and thus it returns with the above error and gets the user logged out.

`package.json

{
"name": "test",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"dev": "ionic serve",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"generate-types": "graphql-codegen --config codegen.yml"
},
"private": true,
"dependencies": {
"@angular/common": "~10.0.0",
"@angular/core": "~10.0.0",
"@angular/forms": "~10.0.0",
"@angular/platform-browser": "~10.0.0",
"@angular/platform-browser-dynamic": "~10.0.0",
"@angular/router": "~10.0.0",
"@capacitor/android": "^2.4.1",
"@capacitor/core": "^2.4.1",
"@capacitor/ios": "^2.4.1",
"@ionic-native/core": "^5.0.0",
"@ionic-native/http": "5.27.0",
"@ionic-native/secure-storage": "5.23.0",
"@ionic-native/splash-screen": "^5.0.0",
"@ionic-native/status-bar": "^5.0.0",
"@ionic/angular": "^5.3.3",
"@oktadev/schematics": "^2.2.0",
"apollo-angular": "^2.0.4",
"cordova-plugin-advanced-http": "3.0.0",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-safariviewcontroller": "1.6.0",
"cordova-plugin-secure-storage-echo": "5.1.1",
"ionic-appauth": "0.5.1",
"jetifier": "^1.6.6",
"rxjs": "~6.5.5",
"tslib": "^2.0.0",
"zone.js": "~0.10.3",
"@apollo/client": "^3.0.0",
"graphql": "^15.0.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.1000.0",
"@angular/cli": "~10.0.5",
"@angular/compiler": "~10.0.0",
"@angular/compiler-cli": "~10.0.0",
"@angular/language-service": "~10.0.0",
"@capacitor/cli": "2.4.1",
"@graphql-codegen/cli": "1.17.10",
"@ionic/angular-toolkit": "^2.3.3",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^12.11.1",
"codelyzer": "^6.0.0",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~5.0.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~3.3.0",
"karma-jasmine-html-reporter": "^1.5.0",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~3.9.5",
"@graphql-codegen/typescript-apollo-angular": "2.0.1",
"@graphql-codegen/typescript": "1.17.10",
"@graphql-codegen/typescript-operations": "1.17.8",
"@graphql-codegen/introspection": "1.18.0"
},
}`

Thanks in Advance

Ionic Capacitor Blank Screen On App Launch When Refresh Token Expired

After a users refresh token has expired, users are stuck on a blank white screen after the splash screen.

"@oktadev/schematics": "^0.8.3"
"ionic-appauth": "0.3.5",

⚡️  Loading app at capacitor://localhost...
⚡️  [log] - onscript loading complete
To Native Cordova ->  File requestAllPaths File866088915 ["options": []]
⚡️  WebView loaded
⚡️  [warn] - [DEPRECATION][Events]: The Events provider is deprecated and it will be removed in the next major release.
  - Use "Observables" for a similar pub/sub architecture: https://angular.io/guide/observables
  - Use "Redux" for advanced state management: https://ngrx.io
⚡️  To Native ->  PushNotifications addListener 52738932
⚡️  To Native ->  PushNotifications addListener 52738933
⚡️  To Native ->  PushNotifications addListener 52738934
⚡️  To Native ->  PushNotifications addListener 52738935
⚡️  To Native ->  LocalNotifications addListener 52738936
⚡️  [log] - Ionic Native: deviceready event fired after 250 ms
⚡️  To Native ->  App addListener 52738937
⚡️  To Native ->  Storage get 52738938
⚡️  TO JS {"value":"{\"access_token\":\"eyJraWQi...
⚡️  [warn] - Native: tried calling StatusBar.styleDefault, but the StatusBar plugin is not installed.
⚡️  [warn] - Install the StatusBar plugin: 'ionic cordova plugin add cordova-plugin-statusbar'
⚡️  To Native ->  SplashScreen hide 52738939
⚡️  TO JS {}
To Native Cordova ->  CordovaHttpPlugin get CordovaHttpPlugin866088916 ["options": [https://dev-XXXXXX.okta.com/oauth2/default/.well-known/openid-configuration, {
    Cookie = "JSESSIONID=8783F468F2B64247576ADA5C0B1B5F54";
}, 60, 1, text]]
⚡️  To Native ->  App addListener 52738940
To Native Cordova ->  CordovaHttpPlugin post CordovaHttpPlugin866088917 ["options": [https://login.example.com/oauth2/default/v1/token, {
    text = "grant_type=refresh_token&client_id=<client id>&redirect_uri=com.okta.dev-XXXXXX%3A%2Fcallback&refresh_token=NOzwzVmCK3Jq...";
}, utf8, {
    "Content-Type" = "application/x-www-form-urlencoded";
    Cookie = "JSESSIONID=63B7DB0D48B8044E44631B161501FF82";
}, 60, 1, text]]
2020-11-03 13:21:40.996503-0600 App[4297:153886] [tcp] tcp_output [C2.1:3] flags=[R.] seq=4215262083, ack=4173473411, win=8191 state=CLOSED rcv_nxt=4173473411, snd_una=4215262052
⚡️  [error] - ERROR Error: Uncaught (in promise): Object: {"status":400,"headers":{"content-type":"application/json;charset=UTF-8","x-rate-limit-limit":"2000","p3p":"CP=\"HONK\"","pragma":"no-cache","x-rate-limit-remaining":"1999","x-xss-protection":"0","server":"nginx","x-okta-request-id":"X6GtxPRTp39hUKnc@IH-WQAAAdY","expires":"0","set-cookie":"sid=\"\"; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/, JSESSIONID=46722BF277E7D57C4DEEC94C53735901; Path=/; Secure; HttpOnly","transfer-encoding":"Identity","cache-control":"no-cache, no-store","date":"Tue, 03 Nov 2020 19:21:40 GMT","strict-transport-security":"max-age=315360000; includeSubDomains","connection":"close","x-content-type-options":"nosniff","x-rate-limit-reset":"1604431360"},"url":"https://login.example.com/oauth2/default/v1/token","error":"{\"error\":\"invalid_grant\",\"error_description\":\"The refresh token is invalid or expired.\"}"}

Add support for Angular 10

If you try to run ng add @oktadev/schematics on a new Angular 10 CLI-generated project, it fails.

$ ng add @oktadev/schematics
Installing packages for tooling via npm.
Installed packages for tooling via npm.
? What is your OIDC app's issuer URL? https://dev-133320.okta.com/oauth2/default
? What is your OIDC app's client ID? 0oa4f47t5iMnGD9b0357
Cannot find module '@schematics/angular/utility/project'
Require stack:
- /Users/mraible/ng10/node_modules/@angular/cdk/schematics/utils/build-component.js
- /Users/mraible/ng10/node_modules/@angular/cdk/schematics/utils/index.js
- /Users/mraible/ng10/node_modules/@angular/cdk/schematics/index.js
- /Users/mraible/ng10/node_modules/schematics-utilities/dist/material/ast/ng-module-imports.js
- /Users/mraible/ng10/node_modules/schematics-utilities/dist/material/index.js
- /Users/mraible/ng10/node_modules/schematics-utilities/dist/index.js
- /Users/mraible/ng10/node_modules/@oktadev/schematics/src/add-auth/index.js
- /Users/mraible/ng10/node_modules/@angular-devkit/schematics/tools/export-ref.js
- /Users/mraible/ng10/node_modules/@angular-devkit/schematics/tools/index.js
- /Users/mraible/ng10/node_modules/@angular/cli/utilities/json-schema.js
- /Users/mraible/ng10/node_modules/@angular/cli/models/command-runner.js
- /Users/mraible/ng10/node_modules/@angular/cli/lib/cli/index.js
- /usr/local/lib/node_modules/@angular/cli/lib/init.js
- /usr/local/lib/node_modules/@angular/cli/bin/ng

I have a hunch this is caused by schematics-utilities: nitayneeman/schematics-utilities#29

AuthSdkError: Unable to retrieve OAuth redirect params storage

Having trouble adding Okta auth to Ionic(Capacitor) app.

I am building Ionic(capacitor)/React mobile app. In documentation it seems that instructions for Okta setup is for Ionic/Angular app.

Below are the steps that I took:

  1. Created an Application in Okta(+ added Login redirect URI)
  2. npm install -g @angular-devkit/schematics-cli
  3. npm i @oktadev/schematics
  4. schematics @oktadev/schematics:add-auth (pasted issuer URL and Client ID)

App works for Web.

Then, I moved to iOS integration.

  1. ionic build
  2. npx cap add ios
  3. npx cap open ios
  4. Added custom scheme to ios/App/App/Info.plist

Then I ran XCode. When I press login button I am being redirected to safari Native browser which opens up Okta login page. I put my credentials(mail,password), app seems to redirect to 192.168.100.2:8100/callback?code="....." where I get this error:

"AuthSdkError: Unable to retrieve OAuth redirect params storage

I am thinking app should redirect back to the mobile app but not sure how it can be done from safari. One thing to point out, I do not have an apple account yet, just testing it out.

Unable To Obtain Server Configuration in ios simulator

Having issue in ios simulator while using "ionic-native-http-connection-backend"

Package:
"@angular/cli": "~10.0.5",
"@oktadev/schematics": "^3.0.0",
"ionic-native-http-connection-backend": "^8.0.0" (without out this package its working )

Issue with a new empty Ionic 6, Angular 15 app on Android emulator/device

After following the documented steps for setting up a new Ionic project, I am unable to authenticate with Okta on an Android device/emulator.

The app works fine from a web browser. It also works fine via iOS. It seems that the app on android thinks it's running on localhost and so Okta is refusing the auth request due to a bad redirect url. If I add http://localhost as a redirect url in Okta, the android app successfully redirects to Okta. However, after signing in with Okta the redirect back to the app then fails. This is obviously because the native app is not running on the web and so it can't resolve the redirect url from Okta of http://localhost.

Attached, is the starter project w/o node_modules. I simply added android to the project via capacitor. No custom content, additional plugins etc have been added. I'm just trying to get a starter project working with Okta from the web, ios and android.

Any ideas how to resolve this issue with android?
secure-ionic.zip

Okta - failure in SecureStorage remove issue on logout- ionic cordova app on iOS

we are getting below error when logging out from app.

Unhandled Promise rejection: Failure in SecureStorage.remove() - The specified item could not be found in the keychain ; Zone: ; Task: Promise.then ; Value: Error: Failure in SecureStorage.remove() - The specified item could not be found in the keychain fail@ionic://localhost/plugins/cordova-plugin-secure-storage-echo/www/securestorage.js:42:45 callbackFromNative@ionic://localhost/cordova.js:297:57 @Ionic://localhost/plugins/cordova-plugin-ionic-webview/src/www/ios/ios-wkwebview-exec.js:129:35 @Ionic://localhost/polyfills.js:173:53 @Ionic://localhost/polyfills.js:1331:41 @Ionic://localhost/polyfills.js:218:61 drainMicroTaskQueue@ionic://localhost/polyfills.js:633:46 promiseReactionJob@[native code]
try { newFunc.apply(console, args); } catch (e) {}
};
}
// ------------------------------------------------------------------------------
// For every function that exists in the original console object, that
// also exists in the new console object, wrap the new console method
// with one that calls both
// ------------------------------------------------------------------------------
for (var key in console) {
   if (typeof WinConsole[key] === 'function') {
       console[key] = wrappedOrigCall(WinConsole[key], console[key]);
  }
}
});
// file: ../cordova-ios/cordova-js-src/plugin/ios/launchscreen.js
define("cordova/plugin/ios/launchscreen", function(require, exports, module) {
var exec = require('cordova/exec');
var launchscreen = {
   show: function () {
       exec(null, null, 'LaunchScreen', 'show', []);
  },
   hide: function () {
       exec(null, null, 'LaunchScreen', 'hide', []);
  }
};
module.exports = launchscreen;
Resource
Scope Chain
Type
MIME Type text/javascript
Resource Type Script
Location
Full URL ionic://localhost/cordova.js
Scheme ionic
Host localhost
Path /cordova.js
Filename cordova.js
Request & Response
Method —
Protocol —
Priority —
Cached No
Status —
Code —
Error
IP Address —
Connection ID

When we try to re-login,(It might be setting the token in secure storage again) it throws exception and couldn't proceed with the app again.

_[Log] sign In (cordova.js, line 1413, x2)
[Log] Checking to see if there is an authorization response to be delivered. (cordova.js, line 1413)
[Error] ERROR
Error: Uncaught (in promise): Error: advanced-http: "data" option is configured to support only following data types: Array, Object processData@ionic://localhost/plugins/cordova-plugin-advanced-http/www/helpers.js:418:22 sendRequest@ionic://localhost/plugins/cordova-plugin-advanced-http/www/public-interface.js:178:28 post@ionic://localhost/plugins/cordova-plugin-advanced-http/www/public-interface.js:200:39 @Ionic://localhost/vendor.js:2824:45 @Ionic://localhost/vendor.js:2784:25 ZoneAwarePromise@ionic://localhost/polyfills.js:1353:41 tryNativePromise@ionic://localhost/vendor.js:2783:31 wrapPromise@ionic://localhost/vendor.js:2807:23 @Ionic://localhost/vendor.js:23678:77 generatorResume@[native code] @Ionic://localhost/vendor.js:30934:75 ZoneAwarePromise@ionic://localhost/polyfills.js:1353:41 _awaiter@ionic://localhost/vendor.js:30930:36 generatorResume@[native code] fulfilled@ionic://localhost/vendor.js:30931:62 onInvoke@ionic://localhost/vendor.js:112176:31 @Ionic://localhost/polyfills.js:173:53 @Ionic://localhost/polyfills.js:1331:41 onInvokeTask@ionic://localhost/vendor.js:112164:35 @Ionic://localhost/polyfills.js:218:61 drainMicroTaskQueue@ionic://localhost/polyfills.js:633:46 promiseReactionJob@[native code]
resolvePromise — zone.js:1255
(anonymous function) — zone.js:1162
rejected — tslib:72:89
onInvoke — core.mjs:25476
(anonymous function) — zone.js:160
(anonymous function) — zone.js:1318
onInvokeTask — core.mjs:25463
(anonymous function) — zone.js:205
drainMicroTaskQueue — zone.js:620

oktadev not working in cordova application

I getting following error ,

Error: node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/definitions-internal.d.ts:16:18 - error TS2430: Interface 'CapacitorInstance' incorrectly extends interface 'CapacitorGlobal'.
Types of property 'Plugins' are incompatible.
Property 'SecureStoragePlugin' is missing in type '{ [pluginName: string]: { [prop: string]: any; }; }' but required in type 'PluginRegistry'.

16 export interface CapacitorInstance extends CapacitorGlobal {


node_modules/capacitor-secure-storage-plugin/dist/esm/definitions.d.ts:3:9
3 SecureStoragePlugin: SecureStoragePluginPlugin;

'SecureStoragePlugin' is declared here.

Error: src/app/app.module.ts:9:10 - error TS2305: Module '"../../node_modules/@ionic/storage/dist/esm"' has no exported member 'IonicStorageModule'.

9 import { IonicStorageModule } from '@ionic/storage';


Error: ./src/app/app.module.ts 17:74-92
"export 'IonicStorageModule' was not found in '@ionic/storage'

Ionic Info;

Ionic:

Ionic CLI : 6.15.0
Ionic Framework : @ionic/angular 5.6.7
@angular-devkit/build-angular : 0.1102.13
@angular-devkit/schematics : 11.2.13
@angular/cli : 11.2.13
@ionic/angular-toolkit : 3.1.1

Utility:

cordova-res : not installed
native-run : not installed

System:

NodeJS : v14.17.0
npm : 6.14.13
OS : macOS Big Sur

Signup Redirection Issue

Users who signup for our app but verify their email from a different device like desktop web. It appears the verify email button is trying to use the app callback url com.okta.dev-123456:/callback?iss=<oauth url>&login_hint=EMAIL_VERIFICATION&session_hint=AUTHENTICATED&login_hint=<registered users email>. This is causing users to see a 404 page when clicking Verify Email.

React in Ionic

It's hard to tell based on the documentation and examples whether this should be usable with React within Ionic. I've been attempting to tackle the problem of wrapping our React app in Ionic, and we use Okta (both okta-auth-js and okta-react) for authentication. With capacitor using capacitor:// for requests within ios I haven't been able to make any progress due to Okta CORS configuration.

@mraible I noticed your issue here https://github.com/wi3land/ionic-appauth-capacitor-demo/issues/2 and had hoped there would be some way to pass an http client to the Okta React SDK (and okta-auth-js for that matter) but again, I haven't had much luck.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.