我正在使用 C# 上的新 MIP SDK 构建 POC 应用程序。要求之一是使用存储在服务器上的用户名/密码。所有示例应用程序都使用 OAuth2 登录,并带有用于用户凭据输入的弹出窗口。我相信正确实施 IAuthDelegate 可能会有所帮助,但内联文档并没有太大帮助。在我的引擎初始化方法中,我遵循 SDK 示例
var authDelegate = new AuthDelegateImplementation(appInfo);
//Initialize and instantiate the File Profile
//Create the FileProfileSettings object
var profileSettings = new FileProfileSettings(
path: "mip_data",
useInMemoryStorage: true,
authDelegate: authDelegate,
consentDelegate: new ConsentDelegateImplementation(),
applicationInfo: appInfo,
minimumLogLevel: LogLevel.Trace);
Console.WriteLine("Load the Profile async and wait for the result");
var fileProfile = Task.Run(async () => await MIP.LoadFileProfileAsync(profileSettings)).Result;
和 AuthDelegateImplementation 具有以下代码
public string AcquireToken(Identity identity, string authority, string resource)
{
AuthenticationContext authContext = new AuthenticationContext(authority);
AuthenticationResult result = authContext.AcquireTokenAsync(
resource: resource,
clientId: _appInfo.ApplicationId,
redirectUri: new Uri(redirectUri),
parameters: new PlatformParameters(PromptBehavior.Auto, null),
userId: UserIdentifier.AnyUser).Result;
return result.AccessToken;
}
谢谢你的帮助,C。