相关疑难解决方法(0)

HttpClientBuilder基本身份验证

自从HttpClient 4.3以来,我一直在使用HttpClientBuilder.我正在连接到具有基本身份验证的REST服务.我正在设置凭据如下:

HttpClientBuilder builder = HttpClientBuilder.create();

// Get the client credentials
String username = Config.get(Constants.CONFIG_USERNAME);
String password = Config.get(Constants.CONFIG_PASSWORD);

// If username and password was found, inject the credentials
if (username != null && password != null)
{
    CredentialsProvider provider = new BasicCredentialsProvider();

    // Create the authentication scope
    AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM);

    // Create credential pair
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);

    // Inject the credentials
    provider.setCredentials(scope, credentials);

    // Set the default credentials provider
    builder.setDefaultCredentialsProvider(provider);
}
Run Code Online (Sandbox Code Playgroud)

但是,这不起作用(我正在使用的REST服务返回401).出了什么问题?

java apache basic-authentication apache-httpclient-4.x

17
推荐指数
2
解决办法
5万
查看次数

在哪个帐户下,Azure Function应用程序中托管的.net控制台应用程序将运行

我开发了一个具有以下主要特征的.net控制台应用程序: -

  1. 与SharePoint联机REST API集成,检索某些列表项,以及修改项字段.
  2. 例如,每天早上1点运行.
  3. 我将在Azure Function应用程序中托管此控制台应用程序.
  4. Azure帐户对sharepoint租户没有任何权限,因为Azure帐户和联机sharepoint位于不同的域中.

所以我不确定控制台应用程序将在哪个帐户运行?

  • 它会在当前的Azure帐户下运行吗?如果是这种情况,那么这将不起作用,因为azure帐户在不同的域上,并且没有对sharepoint的任何权限(它不应该有)?

要么

  • 我可以定义Azure功能应用程序的服务帐户在其下运行,在这种情况下,我可以将服务帐户定义为在线sharepoint内的授权帐户?

要么

  • 我需要在控制台应用程序本身内定义用户名/密码?我不喜欢接近,因为我将在控制台应用程序中公开密码.同时更改用户名的密码意味着我们需要相应地更新控制台应用程序.

所以有人可以就此提出建议吗?谢谢

编辑

管理控制台应用程序身份验证的代码: -

using System; 

using System.Collections.Generic; 

using System.Linq; 

using System.Text; 

using Microsoft.SharePoint.Client; 



namespace O365SPProject 

{ 

    class Program 

    { 





     private class Configuration 

        { 

                public static string ServiceSiteUrl = "https://<tenant>.sharepoint.com"; 

                public static string ServiceUserName = "<user>@<tenant>.onmicrosoft.com"; 

                public static string ServicePassword = "xxxxxxxxxx"; 

        } 



                 static ClientContext GetonlineContext() 

                          { 

                                    var securePassword = new SecureString(); 

                                    foreach (char c in Configuration.ServicePassword) 

                                    { 

                                        securePassword.AppendChar(c); 

                                    } 

                                    var onlineCredentials = new SharePointOnlineCredentials(Configuration.ServiceUserName, securePassword); …
Run Code Online (Sandbox Code Playgroud)

sharepoint azure office365 azure-functions

5
推荐指数
1
解决办法
264
查看次数