Giter VIP home page Giter VIP logo

muharremokutan / okta-react-native-spring-boot-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from oktadev/okta-react-native-spring-boot-example

0.0 0.0 0.0 2.6 MB

React Native + Spring Boot + OIDC

Home Page: https://developer.okta.com/blog/2018/10/10/react-native-spring-boot-mobile-app

License: Apache License 2.0

JavaScript 16.61% Dockerfile 0.05% Shell 0.08% Java 39.27% HTML 2.30% CSS 1.65% TypeScript 39.17% Python 0.21% Objective-C 0.50% Ruby 0.17%

okta-react-native-spring-boot-example's Introduction

React Native mobile app, Spring Boot API, and OIDC Authentication

A React Native and Spring Boot app with the following features:

  • Secure, Spring Boot API
  • React Native app that works on iOS or Android
  • Production API on Cloud Foundry
  • Production API on Google Cloud (via Kubernetes and GKE)
  • OIDC Login with Okta or Keycloak

All generated by JHipster and Ignite JHipster! ๐Ÿ‘โค๏ธ

Please read Build a Mobile App with React Native and Spring Boot to see how this app was created.

Prerequisites: Java 8 and Node 8.

Okta has standards-based APIs that support OIDC, OAuth 2.0, PKCE, and SAML. They're legit, you should check them out.

Getting Started

To download this example locally, run the following commands:

git clone https://github.com/oktadeveloper/okta-react-native-spring-boot-example.git
cd okta-react-native-spring-boot-example

Create a Web Application in Okta

You will need to create an OpenID Connect Application in Okta to get your values to perform authentication. Log in to your Okta Developer account and navigate to Applications > Add Application. Click Web and click Next. Give the app a name you'll remember, specify http://localhost:8080/login as a Login redirect URI, and click Done. Note the client ID and secret. You'll need to copy/paste them into a file in a minute.

Create a ROLE_ADMIN and ROLE_USER group (Users > Groups > Add Group) and add users to them. I recommend adding the account you signed up with to ROLE_ADMIN and creating a new user (Users > Add Person) to add to ROLE_USER.

Navigate to API > Authorization Servers and click the one named default to edit it. Click the Claims tab and Add Claim. Name it "groups", and include it in the ID Token. Set the value type to "Groups" and set the filter to be a Regex of .*. Click Create to complete the process.

Create a file on your hard drive called ~/.okta.env and specify the settings for your app in it.

#!/bin/bash

# Okta with JHipster

export SECURITY_OAUTH2_CLIENT_ACCESS_TOKEN_URI="https://{yourOktaDomain}/oauth2/default/v1/token"
export SECURITY_OAUTH2_CLIENT_USER_AUTHORIZATION_URI="https://{yourOktaDomain}/oauth2/default/v1/authorize"
export SECURITY_OAUTH2_RESOURCE_USER_INFO_URI="https://{yourOktaDomain}/oauth2/default/v1/userinfo"
export SECURITY_OAUTH2_CLIENT_CLIENT_ID="{yourClientId}"
export SECURITY_OAUTH2_CLIENT_CLIENT_SECRET="{yourClientSecret}"

TIP: Make sure your URI variables do not have -admin in them. This is a common mistake.

Create a Native Application in Okta

Ignite JHipster leverages React Native AppAuth, an SDK for communicating with OAuth 2.0 providers. It supports PKCE instead of a client secret, which is a more secure configuration. To use PKCE, you'll need to create a new Native application in Okta.

Log in to your Okta Developer account and navigate to Applications > Add Application. Click Native and click Next. Give the app a name you'll remember (e.g., React Native), select Refresh Token as a grant type, in addition to the default Authorization Code. Change the Login redirect URI to be healthpoints://authorize and click Done.

Modify react-native-app/app/modules/login/login.sagas.js to use the generated clientId.

const { issuer, scope } = authInfo.data
const config = {
  issuer,
  clientId: '{yourNativeClientId}',
  scopes: scope.split(' '),
  redirectUrl: `${AppConfig.appUrlScheme}://authorize`
}

Start Spring Boot API

In the terminal where you want to run the Spring Boot API, run source ~/.okta.env, followed by ./gradlew. You should be able to login using Okta at http://localhost:8080.

Start React Native App

Open a new terminal and navigate to the react-native-app directory. Run yarn to install all the dependencies (brew install yarn if you don't have it). Then run react-native run-ios or react-native run-android to start an emulator with the app running in it. Want more info? Read the blog post. ;)

Links

This example uses some excellent open source projects:

And some kick-ass platforms:

Help

Please post any questions as comments on the companion blog post, or visit our Okta Developer Forums. You can also email [email protected] if you would like to create a support ticket.

License

Apache 2.0, see LICENSE.

okta-react-native-spring-boot-example's People

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.