Ошибка входа и MIP при использовании C#.AccessDeniedException: служба не приняла токен аутентификации. Испытание:['']C#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Ошибка входа и MIP при использовании C#.AccessDeniedException: служба не приняла токен аутентификации. Испытание:['']

Сообщение Anonymous »

Вот сообщение об ошибке, которое я получаю: мы используем логин и пароль для получения токена аутентификации
просто не уверены, какие разрешения нам нужны.
"Microsoft.InformationProtection .Exceptions.AccessDeniedException: служба не приняла токен аутентификации. Вызов:[''] HttpRequest.Id={E0C61208-D90F-49FF-83E0-2A17F8D3DB9A}, CorrelationId=0a882288-d5e3-4b7a-812b-a5dc5a779271, Corre. идентификатор связи .Description=PolicyProfile
в EmailSDK.Program.c__DisplayClass2_0.d.MoveNext() в C:\Users\DaHacker\source\repos\EmailSDK\Program.cs: строка 56"
вот код, который у меня есть, он из краткого руководства MS
MIP.Initialize(MipComponent.File);

// Create ApplicationInfo, setting the clientID from Microsoft Entra App Registration as the ApplicationId.

ApplicationInfo appInfo = new ApplicationInfo()

{

ApplicationId = clientId,

ApplicationName = appName,

ApplicationVersion = "1.0.0"

};

// Instantiate the AuthDelegateImpl object, passing in AppInfo.

AuthDelegateImplementation authDelegate = new AuthDelegateImplementation(appInfo);
// Create MipConfiguration Object

MipConfiguration mipConfiguration = new MipConfiguration(appInfo, "mip_data", LogLevel.Trace ,false);
// Create MipContext using Configuration

using (MipContext mipContext = MIP.CreateMipContext(mipConfiguration))

{

// Initialize and instantiate the File Profile.
// Create the FileProfileSettings object.
// Initialize file profile settings to create/use local state.

FileProfileSettings profileSettings = new FileProfileSettings(mipContext,CacheStorageType.OnDiskEncrypted,
new ConsentDelegateImplementation());

// Load the Profile async and wait for the result.

IFileProfile fileProfile = Task.Run(async () => await MIP.LoadFileProfileAsync(profileSettings)).Result;

// Create a FileEngineSettings object, then use that to add an engine to the profile.

// This pattern sets the engine ID to [email protected], then sets the identity used to create the engine.

FileEngineSettings engineSettings = new FileEngineSettings("[email protected]", authDelegate, "", "en-US");

engineSettings.Identity = new Identity([email protected]);
IFileEngine fileEngine = null;

try

{

fileEngine = Task.Run(async () => await fileProfile.AddEngineAsync(engineSettings)).Result;

}

catch (Exception ex)

{

// Application Shutdown

// handler = null; // This will be used in later quick starts.

fileEngine = null;

fileProfile = null;

mipContext.ShutDown();

}

public AuthDelegateImplementation(ApplicationInfo appInfo)

{

_appInfo = appInfo;
}

public string AcquireToken(Identity identity, string authority, string resource, string claims)

{
authority = https://graph.microsoft.com/.default;
var authorityUri = new Uri(authority);

authority = String.Format([https://%7b0%7d/%7b1%7d]https://{0}/{1}, authorityUri.Host, "10462954-a52f-469d-9f83-8ac832d15e78");

_app = PublicClientApplicationBuilder.Create(_appInfo.ApplicationId).WithTenantId("10462954-a52f-469d-9f83-8ac832d15e78").Build();

var accounts = (_app.GetAccountsAsync()).GetAwaiter().GetResult();

string[] scopes = new[] { "User.Read.All" };

// string[] scopes = new[] { "Files.ReadWrite.All" };

var result = _app.AcquireTokenByUsernamePassword(scopes, "UserEmail:[email protected]", "Password: LetMeIn")

.ExecuteAsync().ConfigureAwait(false).GetAwaiter().GetResult();

return result.AccessToken;

}


Подробнее здесь: https://stackoverflow.com/questions/787 ... e-didnt-ac
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»