GithubHelp home page GithubHelp logo

velocitycubed / capacitor-plugin-msauth Goto Github PK

View Code? Open in Web Editor NEW

This project forked from allenjvn/capacitor-plugin-msauth

0.0 0.0 0.0 386 KB

Capacitor-wrapper for MSAL libraries. Works on iOS, Android and web.

License: Other

JavaScript 1.15% Ruby 2.49% Objective-C 1.95% Java 54.78% TypeScript 8.73% Swift 30.89%

capacitor-plugin-msauth's Introduction

Capacitor Plugin MS auth

This plugin contains an implementation of MSAL for Capacitor.

Installation

  • yarn add @recognizebv/capacitor-plugin-msauth
  • npx cap sync
  • Create an app registration
  • In the app registration, go to Authentication, and then Add platform, and then iOS/macOS
  • You will be asked for a bundle identifier, which you can find in Xcode (under the General tab of your project)
  • Do the same for Android. When asked for the package name, use the name defined in AndroidManifest.xml.
  • In the Signature section, generate a hash for your key. You will need this key hash later.
  • (iOS) Add a new keychain group to your project's Signing & Capabilities. The keychain group should be com.microsoft.adalcache
  • (iOS) Configure URL-schemes by adding the following to your Info.plist file:
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>msauth.$(PRODUCT_BUNDLE_IDENTIFIER)</string>
        </array>
    </dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>msauthv2</string>
    <string>msauthv3</string>
</array>
  • (iOS) Add import RecognizebvCapacitorPluginMsauth to the top of the AppDelegate file to ensure that the library is linked
  • (iOS) if your app's AppDelegate already implements a application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool function, you should add the following code inside this method:
if MsAuthPlugin.checkAppOpen(url: url, options: options) == true {
    return true
}
  • (Android) In the AndroidManifest.xml file, append the following code within the <application> section:
<activity
        android:name="com.microsoft.identity.client.BrowserTabActivity"
        android:exported="true">
    <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="msauth"
              android:host="<package name>"
              android:path="/<key hash, with prepending slash>" />
    </intent-filter>
</activity>

Note that there are two placeholders, one for you package name and one for the key hash.

  • (Android) Add the following snippet to the build.gradle file in the android/ folder
allprojects {
    repositories {
        maven {
            url 'https://pkgs.dev.azure.com/MicrosoftDeviceSDK/DuoSDK-Public/_packaging/Duo-SDK-Feed/maven/v1'
        }
    }
}
  • (Android) Register the plugin in the main activity

Usage

Usage of the plugin is fairly simple, as it has just two methods: login and logout.

Login

import {Plugins} from '@capacitor/core';

const {MsAuthPlugin} = Plugins;

const result = await MsAuthPlugin.login({
    clientId: '<client id>',
    tenant: '<tenant, defaults to common>',
    domainHint: '<domainHint>',
    scopes: ['<scopes, defaults to no scopes>'],
    keyHash: '<Android only, the key hash as obtained above>',
});

const accessToken = result.accessToken;

Logout

import {Plugins} from '@capacitor/core';

const {MsAuthPlugin} = Plugins;

await MsAuthPlugin.logout({
    clientId: '<client id>',
    tenant: '<tenant, defaults to common>',
    domainHint: '<domainHint>',
    keyHash: '<Android only, the key hash as obtained above>',
});

capacitor-plugin-msauth's People

Contributors

allenjvn avatar bartwesselink avatar devjkuba avatar hncleary avatar juulrecognize avatar nielsvandoornrecognize avatar steindekker avatar tom-reinders avatar wslaghekke avatar

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.