简体   繁体   English

OneDrive API 浏览器 C#

[英]OneDrive API browser C#

okay so I have decided to integrate onedrive capablities into my project, I have followed the instructions listed here: https://github.com/OneDrive/onedrive-sample-apibrowser-dotnet好的,所以我决定将 onedrive 功能集成到我的项目中,我已按照此处列出的说明进行操作: https : //github.com/OneDrive/onedrive-sample-apibrowser-dotnet

I have set up the variables that were required to be set up, updated all the nuget libraries, registered the app and set the required permissions for reading and writing ect.我已经设置了需要设置的变量,更新了所有 nuget 库,注册了应用程序并设置了读写等所需的权限。

private const string AadClientId = "6b18d325-####-####-####-##########b0";
private const string AadReturnUrl = "http://localhost:44313";
private const string MsaClientId = "6b18d325-####-####-####-##########b0";

everything seems to be working up to the final login point.一切似乎都在进行到最终登录点。 The project compiles and I click on "sign into aad" I know this part is correct as the login page appears with my registered applications title above the login box.项目编译,我点击“登录 aad”我知道这部分是正确的,因为登录页面出现在登录框上方,我注册的应用程序标题。 the details get entered correctly and it informs you that it is logging in redirecting you and continues to a blank page with the header "continue", everything seems to be set right and going on track but then it hits a snag and returns an message box "Authentication failed", with the detailed exception stating: AADSTS50001: The application named http://localhost:44313 was not found in the tenant named 9188040d-####-####-####-##########ad.详细信息输入正确,它会通知您它正在登录重定向您并继续到标题为“继续”的空白页面,一切似乎都设置正确并按计划进行,但随后遇到障碍并返回一个消息框“身份验证失败”,详细的异常说明:AADSTS50001:在名为 9188040d-####-####-####-### 的租户中找不到名为http://localhost:44313的应用程序#######广告。 This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant.如果应用程序尚未由租户的管理员安装或租户中的任何用户未同意,则可能会发生这种情况。 You might have sent your authentication request to the wrong tenant.您可能将身份验证请求发送给了错误的租户。

Ive read up that I may need to do some things in AzureAD but im not sure, never done anything with one drive before so any assistance in helping me solve this would be great!我已经读到我可能需要在 AzureAD 中做一些事情,但我不确定,以前从来没有用一个驱动器做过任何事情,所以任何帮助我解决这个问题的帮助都会很棒!

Thanks Guys appreciate it!谢谢 伙计们欣赏它! Regards James问候詹姆斯

Registering an app on the Microsoft registration portal gives it access to the consumer version of OneDrive (in the demo, you access it by "Sign in to MSA") - that one should work for you, unless you've also set the MsaReturnUrl to be localhost (in which case, change it to the one originally in the sample).在 Microsoft 注册门户上注册应用程序可以访问 OneDrive 的消费者版本(在演示中,您可以通过“登录到 MSA”访问它)- 除非您还将 MsaReturnUrl 设置为是localhost (在这种情况下,请将其更改为示例中最初的那个)。 You'll be able to log in with your Live ID and access your OneDrive data.您将能够使用您的 Live ID 登录并访问您的 OneDrive 数据。

The business version uses an Azure Active Directory you set up yourself, on Azure.商业版使用您自己在 Azure 上设置的 Azure Active Directory。 Once you have one, that's where you'll be registering your application, adding users, and accessing the ClientId you'll eventually need to put into the code.有了它之后,您就可以在那里注册您的应用程序、添加用户和访问您最终需要放入代码中的 ClientId。

This is probably out of scope for this question - if you simply want to use personal OneDrive accounts, then use the MsaAuthenticationProvider and don't worry about those Aad... properties and the AdalAuthenticationProvider .这可能超出了这个问题的范围 - 如果您只是想使用个人 OneDrive 帐户,则使用MsaAuthenticationProvider并且不要担心那些Aad...属性和AdalAuthenticationProvider

Here you go.给你。 it create application and secret in Azure portal with few clicks.它只需单击几下即可在 Azure 门户中创建应用程序和机密。 https://developer.microsoft.com/en-us/graph/quick-start https://developer.microsoft.com/en-us/graph/quick-start

Please select the type of application that you want to create.请选择您要创建的应用程序类型。 Next click is automated to create application, other things in azure portal on behalf of us.下一次点击自动创建应用程序,代表我们在 azure 门户中创建其他东西。

 IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
       .Create(ClientId)
       .WithTenantId(TenantID)
       .WithClientSecret(ClientSecret)
       .Build();

        ClientCredentialProvider authProvider = new **ClientCredentialProvider**(confidentialClientApplication);
        GraphServiceClient _graphClient = new GraphServiceClient(authProvider);

please change the auth provider accordingly.请相应地更改身份验证提供程序。 the current one is for authenticating application identity(with secret generate in Azure against application).当前用于验证应用程序身份(在 Azure 中针对应用程序生成秘密)。

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

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