GithubHelp home page GithubHelp logo

miszmaniac / msgraph-sdk-android-auth Goto Github PK

View Code? Open in Web Editor NEW

This project forked from microsoftgraph/msgraph-sdk-android-auth

0.0 1.0 0.0 87 KB

MSAL Authentication Provider for Android

License: Other

Java 100.00%

msgraph-sdk-android-auth's Introduction

Microsoft Graph Android Preview Authentication Library

Use MS Graph Android Authentication library to authenticate to use Microsoft Graph API in your Android application! Use this authentication library along with msgraph-sdk-java or msgraph-sdk-java-core to make requests to Microsoft Graph APIs

Important Note about the Microsoft Graph Android Preview Authentication Library

During the preview we may make changes to the API, and other mechanisms of this library, which you will be required to take along with bug fixes or feature improvements. This may impact your application. An API change may require you to update your code. When we provide the General Availability release we will require you to update to the General Availability version within six months, as applications written using a preview version of library may no longer work.

1. Installation

1.1 Install via Gradle

Step 1 : Add this repository in project level build.gradle

allprojects {
    repositories {
        google()
        jcenter()
        jcenter{
            url 'http://oss.jfrog.org/oss-snapshot-local'
        }
    }
}

Step 2 : Add dependency for microsoft-graph-android-auth to your app's build.gradle:

dependency {
    // Include the auth library as a dependency in app level build.gradle
    implementation 'com.microsoft.graph:microsoft-graph-android-auth:0.1.0-SNAPSHOT'
}

Step 3 : Configure your app's AndroidManifest.xml to give Internet permissions

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Step 4 : Add BrowserTabActivity activity in AndroidManifest.xml. Make sure to put your App/Client ID at <YOUR_CLIENT_ID>.

<!--Intent filter to capture System Browser calling back to our app after Sign In-->
<activity
    android:name="com.microsoft.identity.client.BrowserTabActivity">
    <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="msal<YOUR_CLIENT_ID>"
            android:host="auth" />
        </intent-filter>
</activity>

2. Getting started

2.1 Registering your android application

Register your application by following the steps at Register your app with the Azure AD v2.0 endpoint. Once registered you will get CLIENT_ID of your application.

2.2 Create an instance of MSALAuthenticationProvider

PublicClientApplication publicClientApplication = new PublicClientApplication(getApplicationContext(), "CLIENT_ID_OF_YOUR_APPLICATION");
MSALAuthenticationProvider msalAuthenticationProvider = new MSALAuthenticationProvider(
    getActivity(),
    getApplication(),
    publicClientApplication,
    scopes);

2.3 Add auth helper in your Activity

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    msalAuthenticationProvider.handleInteractiveRequestRedirect(requestCode, resultCode, data);
}

2.4 Make requests against the Microsoft Graph REST API

Get your info

Usage in msgraph-sdk-java

IGraphServiceClient graphClient =
  GraphServiceClient
    .builder()
    .authenticationProvider(msalAuthenticationProvider)
    .buildClient();
    
User user = graphClient
  .me()
  .buildRequest()
  .get();
System.out.println(user.displayName);

Usage in msgraph-sdk-java-core

OkHttpClient graphClient = HttpClients.createDefault(msalAuthenticationProvider);
Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/me").build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());

To retrieve the user's drive

Usage in msgraph-sdk-java

IGraphServiceClient graphClient =
  GraphServiceClient
    .builder()
    .authenticationProvider(msalAuthenticationProvider)
    .buildClient();

graphClient
  .me()
  .drive()
  .buildRequest()
  .get(new ICallback<Drive>() {
     @Override
     public void success(final Drive result) {
        System.out.println("Found Drive " + result.id);
     }
     ...
     // Handle failure case
  });

Usage in msgraph-sdk-java-core

OkHttpClient graphClient = HttpClients.createDefault(msalAuthenticationProvider);
Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/me/drive").build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());

3. Issues

For known issues, see issues.

4. Contributions

This library is open for contribution. To contribute to this project, see Contributing.

Thanks to everyone who has already devoted time to improving the library:


Nakul Sabharwal


Deepak Agrawal

This project follows the all-contributors specification. Contributions of any kind are welcome!

5. Supported Java versions

This library supports runtime for Java 7+ and Android API revision 21 and greater.

6. License

Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT license.

7. Third-party notices

Third-party notices

msgraph-sdk-android-auth's People

Contributors

deepak2016 avatar nakulsabharwal avatar

Watchers

 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.