Use Microsoft Graph to access a user’s Microsoft account resources from within a Ruby on Rails web application. This sample uses REST calls directly to Microsoft Graph, and uses the Azure AD v2.0 endpoint for authentication of users' work or school Office 365 accounts.
Ruby HTML CSS
Fetching latest commit…
Cannot retrieve the latest commit at this time.

README.md

Microsoft Graph Ruby on Rails Connect Sample

Build Status

Use Microsoft Graph to access a user’s Microsoft account resources from within a Ruby on Rails web application. This sample uses REST calls directly to the Microsoft Graph endpoint to work with user resources--in this case, to send an email as the user.

The sample uses OmniAuth middleware to authenticate against the Azure AD v2.0 endpoint. The Azure AD v2.0 endpoint enables developers to write a single code flow that handles authentication for both users' work or school (Azure Active Directory) or personal (Microsoft) accounts, including Office 365, Outlook.com, and OneDrive accounts.

The sample also uses the Office Fabric UI for styling and formatting the user experience.

Microsoft Ruby on Rails Connect sample screenshot

Prerequisites

To use this sample, the following are required:

Register the application

Register an app on the Microsoft App Registration Portal. This generates the app ID and password that you'll use to configure the app for authentication.

  1. Sign into the Microsoft App Registration Portal using either your personal or work or school account.

  2. Choose Add an app.

  3. Enter a name for the app, and choose Create application.

    The registration page displays, listing the properties of your app.

  4. Copy the application ID. This is the unique identifier for your app.

  5. Under Application Secrets, choose Generate New Password. Copy the app secret from the New password generated dialog.

    You'll use the application ID and app secret to configure the app.

  6. Under Platforms, choose Add platform > Web.

  7. Make sure the Allow Implicit Flow check box is selected, and enter http://localhost:3000/auth/microsoft_v2_auth/callback as the Redirect URI.

    The Allow Implicit Flow option enables the OpenID Connect hybrid flow. During authentication, this enables the app to receive both sign-in info (the id_token) and artifacts (in this case, an authorization code) that the app uses to obtain an access token.

    The redirect URI http://localhost:3000/auth/microsoft_v2_auth/callback is the value that the OmniAuth middleware is configured to use once it has processed the authentication request.

  8. Choose Save.

Build and run the sample

  1. Download or clone the sample and open it in the editor of your choice.
  2. If you don't already have bundler and rack, you can install them with the following command.

    gem install bundler rack
    
  3. In the config/environment.rb file do the following.

    1. Replace ENTER_YOUR_CLIENT_ID with the app ID of your registered application.
    2. Replace ENTER_YOUR_SECRET with the app secret for your registered application.
  4. Install the Rails application and dependencies with the following command.

    bundle install
    
  5. To start the Rails application, type the following command.

    rackup -p 3000
    
  6. Go to http://localhost:3000 in your web browser.

Contributing

If you'd like to contribute to this sample, see CONTRIBUTING.MD.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Questions and comments

We'd love to get your feedback about the Microsoft Graph Ruby on Rails Connect sample. You can send your questions and suggestions to us in the Issues section of this repository.

Your feedback is important to us. Connect with us on Stack Overflow. Tag your questions with [MicrosoftGraph].

See also

Copyright

Copyright (c) 2016 Microsoft. All rights reserved.