From c1b6c32d2481f652d17cb714a1416aa64ca41ffa Mon Sep 17 00:00:00 2001 From: Charles Zhao Date: Sat, 7 May 2022 11:35:11 +0800 Subject: [PATCH] refactor(console): separate mdx usages from docs --- .gitignore | 3 - packages/console/package.json | 11 +- .../docs/tutorial/integrate-sdk/android.mdx | 273 ++++++++++++++++++ .../docs/tutorial/integrate-sdk/react.mdx | 190 ++++++++++++ .../tutorial/integrate-sdk/react_zh-cn.mdx | 190 ++++++++++++ .../MultiTextInputField/index.tsx | 0 .../Step/index.module.scss | 0 .../Step/index.tsx | 0 .../components/GuideModal/index.tsx | 2 +- packages/console/src/pages/Guide/index.tsx | 7 +- pnpm-lock.yaml | 2 - 11 files changed, 659 insertions(+), 19 deletions(-) create mode 100644 packages/console/src/assets/docs/tutorial/integrate-sdk/android.mdx create mode 100644 packages/console/src/assets/docs/tutorial/integrate-sdk/react.mdx create mode 100644 packages/console/src/assets/docs/tutorial/integrate-sdk/react_zh-cn.mdx rename packages/console/src/{pages/Guide/components => mdx-components}/MultiTextInputField/index.tsx (100%) rename packages/console/src/{pages/Guide/components => mdx-components}/Step/index.module.scss (100%) rename packages/console/src/{pages/Guide/components => mdx-components}/Step/index.tsx (100%) diff --git a/.gitignore b/.gitignore index 302bee1a0..9132715ca 100644 --- a/.gitignore +++ b/.gitignore @@ -17,9 +17,6 @@ node_modules /packages/*/lib /packages/*/dist -# docs copied to admin console -/packages/console/**/*.mdx - # logs logs *.log* diff --git a/packages/console/package.json b/packages/console/package.json index 8836997b0..11ec09e30 100644 --- a/packages/console/package.json +++ b/packages/console/package.json @@ -8,11 +8,10 @@ "scripts": { "preinstall": "npx only-allow pnpm", "precommit": "lint-staged", - "copyfiles": "copyfiles -u 2 \"../docs/**/*.mdx\" src/assets", - "start": "pnpm copyfiles && parcel src/index.html", - "dev": "pnpm copyfiles && PORT=5002 parcel src/index.html --public-url /console --no-cache --hmr-port 6002", + "start": "parcel src/index.html", + "dev": "PORT=5002 parcel src/index.html --public-url /console --no-cache --hmr-port 6002", "check": "tsc --noEmit", - "build": "pnpm check && rm -rf dist && pnpm copyfiles && parcel build src/index.html --no-autoinstall --no-cache --public-url /console", + "build": "pnpm check && rm -rf dist && parcel build src/index.html --no-autoinstall --no-cache --public-url /console", "lint": "eslint --ext .ts --ext .tsx src", "lint:report": "pnpm lint --format json --output-file report.json", "stylelint": "stylelint \"src/**/*.scss\"" @@ -39,7 +38,6 @@ "@types/react-dom": "^17.0.9", "@types/react-modal": "^3.13.1", "classnames": "^2.3.1", - "copyfiles": "^2.4.1", "csstype": "^3.0.11", "dayjs": "^1.10.5", "dnd-core": "^16.0.0", @@ -74,8 +72,7 @@ }, "alias": { "@/*": "./src/$1", - "@theme/*": "./src/mdx-components/$1", - "@components/*": "./src/pages/Guide/components/$1" + "@mdx/components/*": "./src/mdx-components/$1" }, "eslintConfig": { "extends": "@silverhand/react" diff --git a/packages/console/src/assets/docs/tutorial/integrate-sdk/android.mdx b/packages/console/src/assets/docs/tutorial/integrate-sdk/android.mdx new file mode 100644 index 000000000..88c6d82aa --- /dev/null +++ b/packages/console/src/assets/docs/tutorial/integrate-sdk/android.mdx @@ -0,0 +1,273 @@ +import Step from '@mdx/components/Step'; +import Tabs from '@mdx/components/Tabs'; +import TabItem from '@mdx/components/TabItem'; + + props.onNext(1)} +> + +### Prerequisite +* Minimal Android SDK: Level 24 (TBD) + + + + + +```kotlin +dependencies { + implementation("io.logto.sdk:android:1.0.0") +} +``` + + + + + +```groovy +dependencies { + implementation 'io.logto.sdk:android:1.0.0' +} +``` + + + + + + + + props.onNext(2)} +> + +### Configure Redirect URI + +The `Redirect URI` indicates the endpoint that the application used to receive authorization results, which is implemented by the Logto Android SDK internally. + +### Configure Redirect URI in Admin Console + +Add the following value to Redirect URIs on the application settings page. + +```bash +$(LOGTO_REDIRECT_SCHEME)://$(YOUR_APP_PACKAGE)/callback +``` + +Notes: +- `LOGTO_REDIRECT_SCHEME` should be a custom scheme in the reverse domain format. +- Replace `$(LOGTO_REDIRECT_SCHEME)` with your own settings. + +e.g. `io.logto.android://io.logto.sample/callback` + +### Configure Logto Android SDK + + + + + +```kotlin +import io.logto.sdk.android.LogtoClient +import io.logto.sdk.android.type.LogtoConfig + +class MainActivity : AppCompatActivity() { + val logtoConfig = LogtoConfig( + endpoint = "", + appId = "", + scopes = null, + resources = null, + usingPersistStorage = true, + ) + + val logtoClient = LogtoClient(logtoConfig, application) +} +``` + + + + + +```java +import io.logto.sdk.android.LogtoClient; +import io.logto.sdk.android.type.LogtoConfig; + +public class MainActivity extends AppCompatActivity { + private LogtoClient logtoClient; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + LogtoConfig logtoConfig = new LogtoConfig( + "", + "", + null, + null, + true + ); + + logtoClient = new LogtoClient(logtoConfig, getApplication()); + } +} +``` + + + + + +Notes: + +- `` is the logto service running in your machine. If you start logto service in `http://localhost:300` then `` is the Application ID of your application, which is created in the Admin Console. + + + + props.onNext(3)} +> + +### Perform a signing-in action + + + + + +```kotlin +logtoClient.signInWithBrowser( + this, + "io.logto.android://io.logto.sample/callback", +) { logtoException: LogtoException? -> + // custom logic +} +``` + + + + + +```java +logtoClient.signInWithBrowser( + this, + "io.logto.android://io.logto.sample/callback", + logtoException -> { + // custom logic + } +); +``` + + + + + +### Implement your business logic after signing-in. + + + + + +```kotlin +logtoClient.getAccessToken { logtoException: LogtoException?, result: AccessToken? -> + // custom logic +} + +logtoClient.getIdTokenClaims { logtoException: LogtoException?, result: IdTokenCliams? -> + // custom logic +} + +logtoClient.fetchUserInfo { logtoException: LogtoException?, userInfoResponse: UserInfoResponse? -> + // custom logic +} +``` + + + + + +```java +logtoClient.getAccessToken((logtoException, accessToken) -> { + // custom logic +}); + +logtoClient.getIdTokenClaims((logtoException, idTokenClaims) -> { + // custom logic +}); + +logtoClient.fetchUserInfo((logtoException, userInfoResponse) -> { + // custom logic +}); +``` + + + + + + + + props.onNext(4)} +> + +### Perform a signing-out action + + + + + +```kotlin +logtoClient.signOut { logtoException: LogtoException? -> + // custom logic +} +``` + + + + + +```java +logtoClient.signOut(logtoException -> { + // custom logic +}); +``` + + + + + +Notes: + +- `signOut` will always clear local credentials even if errors occurred. + + + + + +- Fetch User Info +- Configure Social Sign-In +- Access Protected API Resources + + diff --git a/packages/console/src/assets/docs/tutorial/integrate-sdk/react.mdx b/packages/console/src/assets/docs/tutorial/integrate-sdk/react.mdx new file mode 100644 index 000000000..24807d7f4 --- /dev/null +++ b/packages/console/src/assets/docs/tutorial/integrate-sdk/react.mdx @@ -0,0 +1,190 @@ +import MultiTextInputField from '@mdx/components/MultiTextInputField'; +import Step from '@mdx/components/Step'; +import Tabs from '@mdx/components/Tabs'; +import TabItem from '@mdx/components/TabItem'; + + props.onNext(1)} +> + + + +```bash +npm i @logto/react +``` + + + + +```bash +yarn add @logto/react +``` + + + + +```bash +pnpm add @logto/react +``` + + + + +```html +