首页 文章

OneDrive for Business Oauth2身份验证

提问于
浏览
1

我正在尝试使用OAuth2.0身份验证协议访问OneDrive for Business . 我已经按照这个例子:http://msdn.microsoft.com/EN-US/library/dn605894(v=office.15).aspx这是我的代码到目前为止:

//  Create an authentication context
        AuthenticationContext ac = new AuthenticationContext(string.Format("https://login.windows.net/{0}",
        ClaimsPrincipal.Current.FindFirst(TenantIdClaimType).Value));

        String id = ClaimsPrincipal.Current.FindFirst(TenantIdClaimType).Value;

        //  Create a client credential based on the application id and secret.
        ClientCredential clcred = new ClientCredential(AppPrincipalId, AppKey);

        //  Using the authorization code acquire an access token.
        var arAD = ac.AcquireTokenByAuthorizationCode(code, new Uri(appRedirect), clcred);

我收到授权码是错误的错误 . 我不明白为什么我收到这条消息 .

任何帮助,将不胜感激!

2 回答

  • 0

    当我尝试手动获取授权代码然后在控制台应用程序中使用它时遇到同样的问题 . 不知道为什么它对我不起作用 .

    但是当我从Web App使用它时,同样的应用程序执行授权并接收代码作为回报(因为我将其指定为returnURL) - 一切正常 .

    我建议你看看这个例子

    https://github.com/AzureADSamples/WebApp-WebAPI-OAuth2-UserIdentity-DotNet

    还有这篇文章要了解在好的情况下发生了什么:

    http://blogs.msdn.com/b/exchangedev/archive/2014/03/25/using-oauth2-to-access-calendar-contact-and-mail-api-in-exchange-online-in-office-365.aspx

    附:它不是OneDrive,但我有完全相同的问题,所以如果你可以使用Exchange或GraphApi,那么它也适用于OneDrive .

  • 0

    如果您以不正确的格式发送身份验证代码,则授权代码出现格式错误 . 可能是您发送的授权码是authcode和会话状态的编码值 . 您需要分离这两个值并仅发送身份验证代码 . 或解码auth代码和会话状态之间的'&'符号(分隔符)并将它们作为两个参数发送 .

    来自ADAL4j的方法 AcquireTokenByAuthorizationCode(...) 仅采用authcode .

相关问题