Connecting to Office 365 is the first step every app must take to start working with Office 365 services and data. This sample shows how to connect and then call one API through Microsoft Graph (previously called Office 365 unified API), and uses the Office Fabric UI to create an Office 365 experience.
To use the Office 365 Ruby Connect sample, the following are required.
-
Ruby 2.1 to run the sample on a development server.
-
Rails framework (the sample has been tested on Rails 4.2).
-
Bundler dependency manager.
-
Rack web server interface for Ruby.
-
An Office 365 account. You can sign up for an Office 365 Developer subscription that includes the resources that you need to start building Office 365 apps.
Note:
If you already have a subscription, the previous link sends you to a page with the message Sorry, you can’t add that to your current account. In that case use an account from your current Office 365 subscription.
If you're already signed in to Office 365, the sign in button in the previous link shows the message Sorry, we can't process your request. In that case sign out from Office 365 on that same page and sign in again. -
A Microsoft Azure Tenant to register your application. Azure Active Directory (AD) provides identity services that applications use for authentication and authorization. A trial subscription can be acquired at Microsoft Azure.
- The
client ID
,key
, andreply URL
values of an application registered in Azure. This sample application must be granted the Send mail as a user permission for Microsoft Graph.
Registering your web application is the first step.
- Sign in to the Azure portal.
- On the top bar, click on your account and under the Directory list, choose the Active Directory tenant where you wish to register your application.
- Click on More Services in the left hand nav, and choose Azure Active Directory.
- Click on App registrations and choose Add.
- Enter a friendly name for the application, for example 'MSGraphConnectRuby' and select 'Web app/API' as the Application Type. For the Sign-on URL, enter ‘http://localhost:3000/auth/azureactivedirectory/callback’. Click on Create to create the application.
- While still in the Azure portal, choose your application, click on Settings and choose Properties.
- Find the Application ID value and copy it to the clipboard.
- Configure Permissions for your application:
- In the Settings menu, choose the Required permissions section, click on Add, then Select an API, and select Microsoft Graph.
- Then, click on Select Permissions and select Sign in and read user profile and Send mail as a user. Click Select and then Done.
- In the Settings menu, choose the Keys section. Enter a description and select a duration for the key. Click Save.
- Important: Copy the key value. You won't be able to access this value again once you leave this pane. You will use this value as your app secret.
-
If you don't already have bundler and rack, you can install them with the following command.
gem install bundler rack
-
In the environment.rb file do the following.
- Replace ENTER_YOUR_CLIENT_ID with the client ID of your registered Azure application.
- Replace ENTER_YOUR_SECRET with the key of your registered Azure application.
- Replace ENTER_YOUR_TENANT with your tenant, in the form your_tenant.onmicrosoft.com.
-
Install the Rails application and dependencies with the following command.
bundle install
-
To start the Rails application, type the following command.
rackup -p 3000
-
Go to
http://localhost:3000
in your web browser.
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 [email protected] with any additional questions or comments.
We'd love to get your feedback about the Office 365 Ruby Connect sample. You can send your questions and suggestions to us in the Issues section of this repository.
Questions about Office 365 development in general should be posted to Stack Overflow. Make sure that your questions or comments are tagged with [Office365] and [API].
- Office 365 APIs platform overview
- Getting started with Office 365 APIs
- Overview of Microsoft Graph
- Other Microsoft Graph connect samples
- Office 365 APIs starter projects and code samples
- Office UI Fabric
Copyright (c) 2015 Microsoft. All rights reserved.