|
| 1 | +<!-- |
| 2 | + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). |
| 3 | + * |
| 4 | + * WSO2 LLC. licenses this file to you under the Apache License, |
| 5 | + * Version 2.0 (the "License"); you may not use this file except |
| 6 | + * in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, |
| 12 | + * software distributed under the License is distributed on an |
| 13 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | + * KIND, either express or implied. See the License for the |
| 15 | + * specific language governing permissions and limitations |
| 16 | + * under the License. |
| 17 | +--> |
| 18 | + |
| 19 | +# Asgardeo React SDK |
| 20 | + |
| 21 | +The Asgardeo React SDK enables to integrate login natively in a react application. |
| 22 | + |
| 23 | +This SDK assists you in creating custom login flows directly within the applications themselves, without relying on browser redirects, thereby prioritizing user experience. |
| 24 | + |
| 25 | +## Getting Started |
| 26 | + |
| 27 | +### Prerequisites |
| 28 | + |
| 29 | +- [Register to Asgardeo and create an organization if you don't already have one](https://wso2.com/asgardeo/docs/get-started/create-asgardeo-account/). The organization name you choose will be referred to as `<org_name>` throughout this document. |
| 30 | +- [Register a standard based application in Asgardeo to integrate your application with Asgardeo](https://wso2.com/asgardeo/docs/guides/applications/register-mobile-app/). You will obtain a `client_id` from Asgardeo for your application which will need to be embedded later for the SDK integration. Also note the redirect URI that you used to create the application, this is also required for the SDK integration. |
| 31 | +- In the created application, go to the **Advanced** tab and [enable the application native authentication for your application](https://is.docs.wso2.com/en/latest/guides/authentication/add-application-native-login/#enable-app-native-authentication). |
| 32 | +- Navigate to the **Protocol** tab in the newly created application and enable the `code` option in the [Allowed Grant Types](https://is.docs.wso2.com/en/latest/references/app-settings/oidc-settings-for-app/#allowed-grant-types) section. |
| 33 | + - Upon enabling, additional fields for `Authorized Redirect URLs` and `Allowed Origins` will appear. Enter your web application's URL in both of these fields. |
| 34 | +- In the same same **Protocol** tab, scroll down to the **Client Authentication** section. There, you will find a checkbox for `Public Client`. Enable this checkbox. |
| 35 | + |
| 36 | +### Installation |
| 37 | + |
| 38 | +To install the Asgardeo React SDK, navigate to your project directory in your terminal and run the following command: |
| 39 | + |
| 40 | +with pnpm: |
| 41 | + |
| 42 | +```bash |
| 43 | +pnpm install @asgardeo/react |
| 44 | +``` |
| 45 | + |
| 46 | +With npm: |
| 47 | + |
| 48 | +```bash |
| 49 | +npm install @asgardeo/react |
| 50 | +``` |
| 51 | + |
| 52 | +With yarn: |
| 53 | + |
| 54 | +```bash |
| 55 | +yarn add @asgardeo/react |
| 56 | +``` |
| 57 | + |
| 58 | +### Wrapping the Application with AsgardeoProvider |
| 59 | + |
| 60 | +After installing the Asgardeo React SDK, you need to wrap your application with the AsgardeoProvider component, which is exposed from the installed package. This component provides the Asgardeo context to all the components in your application. |
| 61 | + |
| 62 | +First, import the AsgardeoProvider from the Asgardeo React SDK: |
| 63 | + |
| 64 | +```ts |
| 65 | +import { AsgardeoProvider } from "@asgardeo/react"; |
| 66 | +``` |
| 67 | + |
| 68 | +Then, wrap your application with the `AsgardeoProvider` and pass the basic configuration to it: |
| 69 | + |
| 70 | +```ts |
| 71 | +<AsgardeoProvider |
| 72 | + config={{ |
| 73 | + baseUrl: "https://api.asgardeo.io/t/org_name", |
| 74 | + clientID: "gqtroUbA1Qsulqr*****", |
| 75 | + scope: ["openid", "internal_login", "profile"], |
| 76 | + signInRedirectURL: "https://domain_name:8080", |
| 77 | + }}> |
| 78 | + <App /> |
| 79 | +</AsgardeoProvider> |
| 80 | +``` |
| 81 | + |
| 82 | +For more details about `AsgardeoProvider` and its properties, you can refer to the [Asgardeo Provider](/react/components/asgardeo-provider). |
0 commit comments