office365_login_flutter 0.0.1 copy "office365_login_flutter: ^0.0.1" to clipboard
office365_login_flutter: ^0.0.1 copied to clipboard

microsoft 365 authentication plugin.

Microsoft 365 is a suite of Microsoft cloud-based services that include popular applications such as Microsoft Word, Excel, PowerPoint, and Outlook, as well as other services such as OneDrive, SharePoint, and Microsoft Teams. To use Microsoft 365, users must first sign in with their Microsoft account or a Microsoft work or school account. The login process requires users to provide their credentials, including their email or username and password.

To integrate Microsoft 365 login functionality into a Flutter app, you can use the office365_login_flutter library. The library provides an easy-to-use interface for integrating OAuth2 authentication with various providers, including Microsoft 365.

Getting Started #

To register your app with the Microsoft Identity Platform, follow these steps:

  1. Go to the Azure Portal and sign in with your Microsoft account. (https://portal.azure.com/)
  2. create a new flutter project and add the dependency in your pubspec.yaml file
    office365_login_flutter: ^0.0.1

Android Setup #

  1. Open the build.gradle file for the app module of your project.
  2. Add the following code to the defaultConfig section in android/app/build.gradle,
    defaultConfig {
         manifestPlaceholders += [appAuthRedirectScheme: "msauth"]
    }
  1. Add the following code to the AndroidManifest.xml file inside the application tag to declare the redirect URI scheme:
        <activity
           android:name="net.openid.appauth.RedirectUriReceiverActivity"
           android:theme="@style/Theme.AppCompat"
           android:launchMode="singleTask"
           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="com.example.flutter_microsoft_login"
           android:path="/VzSiQcXRmi2kyjzcA+mYLEtbGVs=" />
           </intent-filter>
           </activity>
        <meta-data
        android:name="com.microsoft.identity.client.RedirectUri"
        android:value="your redirect uri" />

        <meta-data
            android:name="com.microsoft.identity.client.ClientId"
            android:value="your client id" />

IOS Setup #

  1. Open the Info.plist file of your project.
  2. Add the following keys to the file:
        <key>CFBundleURLTypes</key>
        <array>
        <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLSchemes</key>
        <array>
        <string>com.example.flutterMicrosoftLogin</string>
        </array>
        </dict>
        </array>
        <key>LSApplicationQueriesSchemes</key>
        <array>
        <string>msauth</string>
        <string>msauthv2</string>
        </array>

Please see the example that demonstrates how to sign into the demo IdentityServer instance (https://demo.duendesoftware.com). It has also been tested with Azure B2C and Google Sign-in. It is suggested that developers check the documentation of the identity provider they are using to see what capabilities it supports e.g. how to logout, what values of the prompt parameter it supports etc. API docs can be found here

Set up office365_login in your Flutter app #

The first step is to create an instance of the plugin

    final AuthorizationTokenResponse? result = await  const Office365Login().authentication(
      AuthorizationTokenRequest(
        'b4b47313-22b0-4993-b9b9-a4725372df9e',
        'msauth://com.example.flutter_microsoft_login/VzSiQcXRmi2kyjzcA%2BmYLEtbGVs%3D',
        discoveryUrl: 'https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration',
        scopes: ['openid','profile', 'email',],
        serviceConfiguration: const AuthorizationServiceConfiguration(
          authorizationEndpoint: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
          tokenEndpoint: 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
        ),
      ),
    );