You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Ruby on Rails的内网系统Office365认证及用户数据获取咨询

完全可以通过Microsoft Graph API实现你的需求!

Absolutely! You can absolutely build your Ruby on Rails intranet with Office 365 authentication and fetch user avatars, calendar data, and other basic info using Microsoft Graph API. Let me break this down clearly for you:

1. Office 365 User Authentication for Your Rails App

Third-party apps like your intranet system absolutely can use Microsoft Graph to handle Office 365 user authentication. Here's how it works:

  • First, register your Rails app in Azure Active Directory (Azure AD): Create a "Web" type app registration, and configure the redirect URI (e.g., https://your-intranet-domain/auth/microsoft_graph/callback) where Microsoft will send users after they log in.
  • Use the OAuth 2.0 Authorization Code Flow: When users click "Log in with Office 365", they'll be redirected to Microsoft's login page. After entering their Office 365 credentials and granting your app permission, Microsoft will send an authorization code back to your Rails app. You'll exchange this code for an access token (and refresh token, for keeping sessions alive).
  • Validate the user: Once you have the access token, call the GET /me endpoint to fetch the user's basic profile data, confirming their identity and completing the login flow.

2. Fetching User Avatars & Calendar Data

With a valid access token and the right permissions, you can pull all the data you need via Microsoft Graph:

  • User Avatar: Call GET /me/photo/$value to fetch the raw binary data of the user's profile photo, which you can display directly in your Rails app. Alternatively, the GET /me response includes a photo link you can use if you prefer.
  • Calendar Information:
    • Call GET /me/calendars to get a list of all the user's calendars.
    • Call GET /me/calendar/events to fetch events from the user's default calendar. You can add filters (like $filter=start/dateTime ge '2024-06-01T00:00:00Z') to narrow down events by date range.

3. Rails Development Tips

To simplify integration, use these well-maintained Ruby gems:

  • omniauth-microsoft_graph: Handles all the OAuth 2.0 heavy lifting—redirects, code exchanges, and session management—so you don't have to build the flow from scratch.
  • microsoft_graph: A Ruby wrapper for Microsoft Graph API that lets you call endpoints with clean Ruby methods instead of raw HTTP requests.

Permission Setup Notes

In your Azure AD app registration, you'll need to request Delegated Permissions (since you're accessing data on behalf of the logged-in user):

  • User.Read: Required to fetch basic user profile data and avatars.
  • Calendars.Read: Required to read the user's calendar events.

If your company uses a managed Office 365 tenant, an admin can grant these permissions for all users upfront, so individual employees won't have to approve the permissions each time they log in.

All in all, Microsoft Graph API is a perfect fit for your use case—it will let you replace SharePoint's authentication with seamless Office 365 integration and pull all the user and calendar data your Rails intranet needs.

内容的提问来源于stack exchange,提问作者Lunistep

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 05:29:34