简体   繁体   English

Office 365 API MVC身份验证

[英]Office 365 API MVC Authentification

I am using the MVC Office 365 API libraries and I would like to archieve the following thing: Logging into User-Accounts where I know the username / password and then get there calendar entries. 我正在使用MVC Office 365 API库,我想归档以下内容:登录到我知道用户名/密码的用户帐户,然后到达日历条目。

What I have so far is code that makes this redirect and ask the user to enter credentials. 到目前为止,我所拥有的是使此重定向并要求用户输入凭据的代码。 But how can I log in for them wihtout asking? 但是我该如何在不询问的情况下为他们登录? The idea is to get the calendar entries for every user (lets say 20 of them) automatically every few minutes. 这个想法是每隔几分钟自动为每个用户(例如说20个)获取日历项。

public static async Task<IEvent[]> GetCalendarEvents()
{
    var client = await EnsureClientCreated();

    // Obtain calendar event data
    var eventsResults = await (from i in client.Me.Events
                                where i.End >= DateTimeOffset.UtcNow
                                select i).Take(10).ExecuteAsync();

    var events = eventsResults.CurrentPage.OrderBy(e => e.Start).ToArray();

    return events;
}

public static async Task<ExchangeClient> EnsureClientCreated()
{
    var _discoveryContext = await CacheHelper.GetDiscoveryContext();
    var dcr = await _discoveryContext.DiscoverResourceAsync(ServiceResourceId);
    return new ExchangeClient(ServiceEndpointUri, async () =>
    {
        return (await _discoveryContext.AuthenticationContext.AcquireTokenByRefreshTokenAsync(new SessionCache().Read("RefreshToken"),
            new Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential(_discoveryContext.AppIdentity.ClientId, _discoveryContext.AppIdentity.ClientSecret),
            ServiceResourceId))
            .AccessToken;
    });
}

Late answer I know. 我知道最新答案。 But if your still looking for this, or anyone else, this blog may be what your looking for. 但是,如果您仍在寻找此博客或其他任何人,则此博客可能是您在寻找的博客。

http://blogs.msdn.com/b/exchangedev/archive/2015/01/22/building-demon-or-service-apps-with-office-365-mail-calendar-and-contacts-apis-oauth2-client-credential-flow.aspx http://blogs.msdn.com/b/exchangedev/archive/2015/01/22/building-demon-or-service-apps-with-office-365-mail-calendar-and-contacts-apis-oauth2-客户端凭证,flow.aspx

A daemon/service app will get calendar events on behalf of a user, proving the user and the app are registered under the same tennat/organisation. 守护程序/服务应用程序将代表用户获取日历事件,证明该用户和该应用程序是在相同的机构/组织下注册的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM