From d753855f1c547a05d6db51655a8ffa317b0b3e28 Mon Sep 17 00:00:00 2001 From: Kacper Wiszczuk Date: Mon, 8 Apr 2024 15:31:04 +0200 Subject: [PATCH] feat(msft): implement microsoft plugin (#11) * feat(msft): implement microsoft plugin Signed-off-by: Kacper Wiszczuk * feat: cd for msft plugin Signed-off-by: Kacper Wiszczuk * fix: remove unnecessary junk Signed-off-by: Kacper Wiszczuk --------- Signed-off-by: Kacper Wiszczuk --- .github/workflows/cd.yml | 5 +- apps/sample-app/android/app/.gitignore | 1 + apps/sample-app/android/app/build.gradle | 28 +++++ .../android/app/src/main/res/raw/.gitkeep | 0 apps/sample-app/package.json | 1 + apps/sample-app/src/app/SignedInProvider.tsx | 14 ++- apps/sample-app/src/screens/HomeScreen.tsx | 11 ++ bun.lockb | Bin 406072 -> 405888 bytes .../reactnative/auth/core/OmhAuthModule.kt | 12 +- packages/core/src/AuthModule.ts | 8 +- packages/core/src/types.ts | 4 + .../auth/plugin/dropbox/OmhDropboxModule.kt | 4 +- .../auth/plugin/facebook/OmhFacebookModule.kt | 4 +- .../auth/plugin/google/OmhGoogleModule.kt | 3 +- .../plugin-microsoft/android/build.gradle | 106 ++++++++++++++++++ .../android/gradle.properties | 9 ++ .../android/src/main/AndroidManifest.xml | 3 + .../android/src/main/AndroidManifestNew.xml | 19 ++++ .../plugin/microsoft/OmhMicrosoftModule.kt | 33 ++++++ .../plugin/microsoft/OmhMicrosoftPackage.kt | 17 +++ packages/plugin-microsoft/package.json | 11 ++ packages/plugin-microsoft/src/index.tsx | 10 ++ packages/plugin-microsoft/src/types.ts | 5 + 23 files changed, 290 insertions(+), 18 deletions(-) create mode 100644 apps/sample-app/android/app/.gitignore create mode 100644 apps/sample-app/android/app/src/main/res/raw/.gitkeep create mode 100644 packages/plugin-microsoft/android/build.gradle create mode 100644 packages/plugin-microsoft/android/gradle.properties create mode 100644 packages/plugin-microsoft/android/src/main/AndroidManifest.xml create mode 100644 packages/plugin-microsoft/android/src/main/AndroidManifestNew.xml create mode 100644 packages/plugin-microsoft/android/src/main/java/com/openmobilehub/reactnative/auth/plugin/microsoft/OmhMicrosoftModule.kt create mode 100644 packages/plugin-microsoft/android/src/main/java/com/openmobilehub/reactnative/auth/plugin/microsoft/OmhMicrosoftPackage.kt create mode 100644 packages/plugin-microsoft/package.json create mode 100644 packages/plugin-microsoft/src/index.tsx create mode 100644 packages/plugin-microsoft/src/types.ts diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 9264e20..7cd8e8d 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -34,7 +34,10 @@ jobs: echo GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }} >> ${{ env.SAMPLE_APP_PATH }}/local.properties && echo FACEBOOK_APP_ID=${{ secrets.FACEBOOK_APP_ID }} >> ${{ env.SAMPLE_APP_PATH }}/local.properties && echo FACEBOOK_CLIENT_TOKEN=${{ secrets.FACEBOOK_CLIENT_TOKEN }} >> ${{ env.SAMPLE_APP_PATH }}/local.properties && - echo DROPBOX_APP_KEY=${{ secrets.DROPBOX_APP_KEY }} >> ${{ env.SAMPLE_APP_PATH }}/local.properties + echo DROPBOX_APP_KEY=${{ secrets.DROPBOX_APP_KEY }} >> ${{ env.SAMPLE_APP_PATH }}/local.properties && + echo MICROSOFT_CLIENT_ID=${{ secrets.MICROSOFT_CLIENT_ID }} >> ${{ env.SAMPLE_APP_PATH }}/local.properties && + echo MICROSOFT_HOST_PATH=com.openmobilehub.reactnative.auth.sample.MainApplication && + echo MICROSOFT_SIGNATURE_HASH=${{ secrets.MICROSOFT_SIGNATURE_HASH }} >> ${{ env.SAMPLE_APP_PATH }}/local.properties - name: Build release run: | diff --git a/apps/sample-app/android/app/.gitignore b/apps/sample-app/android/app/.gitignore new file mode 100644 index 0000000..bfb3d45 --- /dev/null +++ b/apps/sample-app/android/app/.gitignore @@ -0,0 +1 @@ +/src/main/res/raw/ms_auth_config.json diff --git a/apps/sample-app/android/app/build.gradle b/apps/sample-app/android/app/build.gradle index 8ce2efa..a9ed32d 100644 --- a/apps/sample-app/android/app/build.gradle +++ b/apps/sample-app/android/app/build.gradle @@ -81,6 +81,34 @@ android { targetSdkVersion rootProject.ext.targetSdkVersion versionCode 1 versionName "1.0" + + def properties = new Properties() + properties.load(project.rootProject.file("local.properties").newDataInputStream()) + + file("./src/main/res/raw/ms_auth_config.json").write( + """ +{ + "client_id": "${properties.getProperty("MICROSOFT_CLIENT_ID")}", + "authorization_user_agent": "DEFAULT", + "redirect_uri": "msauth://${properties.getProperty("MICROSOFT_HOST_PATH")}/${ + URLEncoder.encode( + properties.getProperty("MICROSOFT_SIGNATURE_HASH"), + "UTF-8" + ) + }", + "authorities": [ + { + "type": "AAD", + "audience": { + "type": "AzureADandPersonalMicrosoftAccount", + "tenant_id": "common" + } + } + ], + "account_mode": "SINGLE" +} + """.strip().stripIndent() + ) } signingConfigs { debug { diff --git a/apps/sample-app/android/app/src/main/res/raw/.gitkeep b/apps/sample-app/android/app/src/main/res/raw/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/apps/sample-app/package.json b/apps/sample-app/package.json index 49c4230..231ec8d 100644 --- a/apps/sample-app/package.json +++ b/apps/sample-app/package.json @@ -14,6 +14,7 @@ "@omh/react-native-auth-google": "workspace:*", "@omh/react-native-auth-facebook": "workspace:*", "@omh/react-native-auth-dropbox": "workspace:*", + "@omh/react-native-auth-microsoft": "workspace:*", "@react-native-async-storage/async-storage": "^1.23.1", "@react-navigation/native": "^6.1.17", "@react-navigation/native-stack": "^6.9.26", diff --git a/apps/sample-app/src/app/SignedInProvider.tsx b/apps/sample-app/src/app/SignedInProvider.tsx index 0becf21..fa427ca 100644 --- a/apps/sample-app/src/app/SignedInProvider.tsx +++ b/apps/sample-app/src/app/SignedInProvider.tsx @@ -3,12 +3,14 @@ import React from 'react'; import DropboxAuth from '@omh/react-native-auth-dropbox'; import FacebookAuth from '@omh/react-native-auth-facebook'; import GoogleAuth from '@omh/react-native-auth-google'; +import MicrosoftAuth from '@omh/react-native-auth-microsoft'; import AsyncStorage from '@react-native-async-storage/async-storage'; export const PROVIDER_NAMES = { GOOGLE: 'google', FACEBOOK: 'facebook', DROPBOX: 'dropbox', + MICROSOFT: 'microsoft', } as const; type ObjectValues = T[keyof T]; @@ -18,14 +20,20 @@ export type Providers = ObjectValues; export const getAuthProvider = async (provider: Providers) => { switch (provider) { case PROVIDER_NAMES.GOOGLE: - await GoogleAuth.initialize(['openid', 'email', 'profile']); + await GoogleAuth.initialize({scopes: ['openid', 'email', 'profile']}); return GoogleAuth; case PROVIDER_NAMES.FACEBOOK: - await FacebookAuth.initialize(['public_profile', 'email']); + await FacebookAuth.initialize({scopes: ['public_profile', 'email']}); return FacebookAuth; case PROVIDER_NAMES.DROPBOX: - await DropboxAuth.initialize(['account_info.read']); + await DropboxAuth.initialize({scopes: ['account_info.read']}); return DropboxAuth; + case PROVIDER_NAMES.MICROSOFT: + await MicrosoftAuth.initialize({ + scopes: ['User.Read'], + configFileName: 'ms_auth_config', + }); + return MicrosoftAuth; } }; diff --git a/apps/sample-app/src/screens/HomeScreen.tsx b/apps/sample-app/src/screens/HomeScreen.tsx index 7d67450..68b261b 100644 --- a/apps/sample-app/src/screens/HomeScreen.tsx +++ b/apps/sample-app/src/screens/HomeScreen.tsx @@ -34,11 +34,22 @@ export default function HomeScreen() { signInWithProvider(PROVIDER_NAMES.DROPBOX); } + async function onMicrosoftSignIn() { + const microsoftAuthProvider = await getAuthProvider( + PROVIDER_NAMES.MICROSOFT, + ); + + await microsoftAuthProvider.signIn(); + + signInWithProvider(PROVIDER_NAMES.MICROSOFT); + } + return (