本文整理汇总了C#中Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult类的典型用法代码示例。如果您正苦于以下问题:C# AuthenticationResult类的具体用法?C# AuthenticationResult怎么用?C# AuthenticationResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AuthenticationResult类属于Microsoft.IdentityModel.Clients.ActiveDirectory命名空间,在下文中一共展示了AuthenticationResult类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: JSONResponse
internal static JObject JSONResponse( string url, HttpMethod method, AuthenticationResult authResult, string apiPayload = "" )
{
HttpWebRequest webClientRequest;
webClientRequest = WebRequest.CreateHttp( new Uri( url ) );
webClientRequest.Method = method.ToString();
webClientRequest.Headers.Add( "Authorization", authResult.CreateAuthorizationHeader() );
if ( method != HttpMethod.Get )
{
using ( var writer = new StreamWriter( webClientRequest.GetRequestStream() ) )
{
writer.Write( apiPayload );
}
}
WebResponse response;
JObject jsonResponse = null;
try
{
response = webClientRequest.GetResponse();
}
catch ( WebException webEx )
{
response = webEx.Response;
}
using ( var reader = new StreamReader( response.GetResponseStream() ) )
{
jsonResponse = JObject.Parse( reader.ReadToEnd() );
}
return jsonResponse;
}
开发者ID:rjmporter,项目名称:TscOdfbUtility,代码行数:30,代码来源:Program.cs
示例2: AuthenticateAsync
public async Task<bool> AuthenticateAsync()
{
await GetConfigAsync();
// prompts the user for authentication
_AuthenticationResult = await _Authenticator.Authenticate(_TenantAuthority, _ResourceUri, _AzureAuthenticationClientId, _ReturnUri);
var accessToken = await GetTokenAsync();
// instantiate an ActiveDirectoryClient to query the Graph API
var activeDirectoryGraphApiClient = new ActiveDirectoryClient(
new Uri(new Uri(_ResourceUri), _AzureGraphApiClientId),
() => Task.FromResult<string>(accessToken)
);
// query the Azure Graph API for some detailed user information about the logged in user
//This is done differently based on platform because if this is not awaited in iOS, it crashes
//the app. Android is done this way to correct login issues that were previously occurring.
if (Xamarin.Forms.Device.OS == TargetPlatform.Android)
{
Task.Run(() =>
{
LogUserInfo(activeDirectoryGraphApiClient);
});
}
else
{
await Task.Run(async () =>
{
LogUserInfo(activeDirectoryGraphApiClient);
});
}
return true;
}
开发者ID:wanddy,项目名称:app-crm,代码行数:35,代码来源:AuthenticationService.cs
示例3: AuthenticateAsync
public async Task<bool> AuthenticateAsync()
{
await GetConfigAsync();
// prompts the user for authentication
_AuthenticationResult = await _Authenticator.Authenticate(_TenantAuthority, _ResourceUri, _AzureAuthenticationClientId, _ReturnUri);
var accessToken = await GetTokenAsync();
// instantiate an ActiveDirectoryClient to query the Graph API
var activeDirectoryGraphApiClient = new ActiveDirectoryClient(
new Uri(new Uri(_ResourceUri), _AzureGraphApiClientId),
() => Task.FromResult<string>(accessToken)
);
// query the Azure Graph API for some detailed user information about the logged in user
var userFetcher = activeDirectoryGraphApiClient.Me.ToUser();
var user = await userFetcher.ExecuteAsync();
// record some info about the logged in user with Xamarin Insights
Insights.Identify(
_AuthenticationResult.UserInfo.UniqueId,
new Dictionary<string, string>
{
{ Insights.Traits.Email, user.UserPrincipalName },
{ Insights.Traits.FirstName, user.GivenName },
{ Insights.Traits.LastName, user.Surname },
{ "Preferred Language", user.PreferredLanguage }
}
);
return true;
}
开发者ID:nikhil-rajan,项目名称:XamarinCRM,代码行数:33,代码来源:AuthenticationService.cs
示例4: TokenCacheInfo
public TokenCacheInfo(string tenantId, string appId, string appKey, string resource, AuthenticationResult result)
: this(resource, result)
{
AppId = appId;
AppKey = appKey;
TenantId = tenantId;
}
开发者ID:vansonvinhuni,项目名称:ARMClient,代码行数:7,代码来源:TokenCacheInfo.cs
示例5: ServicePrincipalAccessToken
public ServicePrincipalAccessToken(AdalConfiguration configuration, AuthenticationResult authResult, ServicePrincipalTokenProvider tokenProvider, string appId)
{
Configuration = configuration;
AuthResult = authResult;
this.tokenProvider = tokenProvider;
this.appId = appId;
}
开发者ID:khoatle,项目名称:azure-powershell,代码行数:7,代码来源:ServicePrincipalTokenProvider.cs
示例6: AccessToken
//Get access token:
// To call a Data Catalog REST operation, create an instance of AuthenticationContext and call AcquireToken
// AuthenticationContext is part of the Active Directory Authentication Library NuGet package
// To install the Active Directory Authentication Library NuGet package in Visual Studio,
// run "Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory" from the NuGet Package Manager Console.
static AuthenticationResult AccessToken()
{
if (authResult == null)
{
//Resource Uri for Data Catalog API
string resourceUri = "https://datacatalog.azure.com";
//To learn how to register a client app and get a Client ID, see https://msdn.microsoft.com/en-us/library/azure/mt403303.aspx#clientID
string clientId = clientIDFromAzureAppRegistration;
//A redirect uri gives AAD more details about the specific application that it will authenticate.
//Since a client app does not have an external service to redirect to, this Uri is the standard placeholder for a client app.
string redirectUri = "https://login.live.com/oauth20_desktop.srf";
// Create an instance of AuthenticationContext to acquire an Azure access token
// OAuth2 authority Uri
string authorityUri = "https://login.windows.net/common/oauth2/authorize";
AuthenticationContext authContext = new AuthenticationContext(authorityUri);
// Call AcquireToken to get an Azure token from Azure Active Directory token issuance endpoint
// AcquireToken takes a Client Id that Azure AD creates when you register your client app.
authResult = authContext.AcquireToken(resourceUri, clientId, new Uri(redirectUri), PromptBehavior.RefreshSession);
}
return authResult;
}
开发者ID:torevor,项目名称:data-catalog-dotnet-get-started,代码行数:31,代码来源:Program.cs
示例7: GetDrivesApiCallForSelectedFile
public static async Task<string> GetDrivesApiCallForSelectedFile( this SharePointOnlineUri fileHandlerFileGetOrPutUri, Guid FileHandlerFileId, AuthenticationResult SharepointAdalAuthResult )
{
using ( var context = new ClientContext( fileHandlerFileGetOrPutUri.GetSharePointWebUrlFromFileHandlerGetPutUri() ) )
{
context.ExecutingWebRequest += ( sender, e ) =>
{
e.WebRequestExecutor.RequestHeaders.Add( "Authorization", SharepointAdalAuthResult.CreateAuthorizationHeader() );
};
var webRequestUrl = await Task.Run( () =>
{
return GetSharePointMetaData( context, FileHandlerFileId );
} );
JObject oneDriveResult = await Task.Run( async () =>
{
string result = string.Empty;
using ( var request = new WebClient() )
{
request.Headers.Add( "Authorization", SharepointAdalAuthResult.CreateAuthorizationHeader() );
result = await request.DownloadStringTaskAsync( webRequestUrl );
}
return JObject.Parse( result );
} );
var driveId = oneDriveResult["parentReference"]["driveId"].ToString();
var itemId = oneDriveResult["id"].ToString();
return $"drives/{driveId}/items/{itemId}";
}
}
开发者ID:rjmporter,项目名称:TscOdfbUtility,代码行数:32,代码来源:Class1.cs
示例8: SaveAuthToken
private static async Task SaveAuthToken(AuthState authState, AuthenticationResult authResult)
{
var idToken = SessionToken.ParseJwtToken(authResult.IdToken);
string username = null;
var userNameClaim = idToken.Claims.FirstOrDefault(x => x.Type == "upn");
if (userNameClaim != null)
username = userNameClaim.Value;
using (var db = new AddInContext())
{
var existingToken =
await
db.SessionTokens.FirstOrDefaultAsync(
t => t.Provider == Settings.AzureADAuthority && t.Id == authState.stateKey);
if (existingToken != null)
{
db.SessionTokens.Remove(existingToken);
}
var token = new SessionToken()
{
Id = authState.stateKey,
CreatedOn = DateTime.Now,
AccessToken = authResult.AccessToken,
Provider = Settings.AzureADAuthority,
Username = username
};
db.SessionTokens.Add(token);
await db.SaveChangesAsync();
}
}
开发者ID:dougperkes,项目名称:Office-Add-in-AspNetMvc-ServerAuth,代码行数:30,代码来源:AzureADAuthController.cs
示例9: MakeMeAvailable
public static bool MakeMeAvailable(HttpClient httpClient, AuthenticationResult ucwaAuthenticationResult, String ucwaMakeMeAvailableRootUri,
UcwaMakeMeAvailableObject ucwaMyPresenceObject)
{
string makeMeAvailableResults = string.Empty;
Console.WriteLine("URI is " + ucwaMakeMeAvailableRootUri);
httpClient.DefaultRequestHeaders.Clear();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ucwaAuthenticationResult.AccessToken);
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var makeMeAvailablePostData = JsonConvert.SerializeObject(ucwaMyPresenceObject);
Console.WriteLine("MakeMeAvailable POST data is " + makeMeAvailablePostData);
var httpResponseMessage =
httpClient.PostAsync(ucwaMakeMeAvailableRootUri, new StringContent(makeMeAvailablePostData, Encoding.UTF8,
"application/json")).Result;
Console.WriteLine("MakeMeAvailable response is " + httpResponseMessage.Content.ReadAsStringAsync().Result);
Console.WriteLine("MakeMeAvailable response should be empty");
if (httpResponseMessage.Content.ReadAsStringAsync().Result == String.Empty)
{
Console.WriteLine("MakeMeAvailable call succeeded");
return true;
}
Console.WriteLine("MakeMeAvailable call failed");
return false;
}
开发者ID:tamhinsf,项目名称:ucwa-sfbo-console,代码行数:26,代码来源:UcwaMakeMeAvailable.cs
示例10: ApplicationTokenProvider
/// <summary>
/// Create an application token provider that can retrieve tokens for the given application from the given context, using the given audience
/// and credential store.
/// See <see href="https://azure.microsoft.com/en-us/documentation/articles/active-directory-devquickstarts-dotnet/">Active Directory Quickstart for .Net</see>
/// for detailed instructions on creating an Azure Active Directory application.
/// </summary>
/// <param name="context">The authentication context to use when retrieving tokens.</param>
/// <param name="tokenAudience">The token audience to use when retrieving tokens</param>
/// <param name="clientId">The client Id for this active directory application</param>
/// <param name="credentialStore">The source of authentication information for this application.</param>
/// <param name="authenticationResult">The authenticationResult of initial authentication with the application credentials.</param>
public ApplicationTokenProvider(AuthenticationContext context, string tokenAudience, string clientId,
IApplicationCredentialProvider credentialStore, AuthenticationResult authenticationResult)
{
if (authenticationResult == null)
{
throw new ArgumentNullException("authenticationResult");
}
Initialize(context, tokenAudience, clientId, credentialStore, authenticationResult, authenticationResult.ExpiresOn);
}
开发者ID:tonytang-microsoft-com,项目名称:autorest,代码行数:21,代码来源:ApplicationTokenProvider.cs
示例11: DisplayToken
private void DisplayToken(AuthenticationResult result)
{
if (!string.IsNullOrEmpty(result.AccessToken))
{
this.AccessToken.Text = result.AccessToken;
}
else
{
this.AccessToken.Text = result.ErrorDescription;
}
}
开发者ID:ankurchoubeymsft,项目名称:azure-activedirectory-library-for-dotnet,代码行数:11,代码来源:MainPage.xaml.cs
示例12: SharePointAccessInfo
/// <summary>
/// Initializes a new instance of the <see cref="SharePointAccessInfo"/> class.
/// </summary>
/// <param name="webUrl">The web URL.</param>
/// <param name="authenticationResult">The authentication result.</param>
public SharePointAccessInfo(string webUrl, AuthenticationResult authenticationResult)
: this(webUrl)
{
// Dont expose the refresh token on the client side!
AccessToken = authenticationResult.AccessToken;
ExpiresOn = authenticationResult.ExpiresOn;
TenantId = authenticationResult.TenantId;
UserId = authenticationResult.UserInfo.UniqueId;
RefreshToken = authenticationResult.RefreshToken;
UserEmail = authenticationResult.UserInfo.DisplayableId;
User = new SharePointUser();
}
开发者ID:cheekyeagle,项目名称:Word-Add-in-ClauseLibrary-Code-Sample,代码行数:17,代码来源:SharePointAccessInfo.cs
示例13: Logout
public async Task<bool> Logout()
{
await Task.Factory.StartNew(async () =>
{
var success = await _Authenticator.DeAuthenticate(_TenantAuthority);
if (!success)
{
throw new Exception("Failed to DeAuthenticate!");
}
_AuthenticationResult = null;
});
return true;
}
开发者ID:kirillg,项目名称:demo-xamarincrm,代码行数:13,代码来源:AuthenticationService.cs
示例14: CacheAuthenticationResult
public static void CacheAuthenticationResult(AuthenticationResult authenticationResult) {
session["UserHasAuthenticated"] = "true";
// cache user authentication info
session["tenant_id"] = authenticationResult.TenantId;
session["user_id"] = authenticationResult.UserInfo.UniqueId;
session["user_name"] = authenticationResult.UserInfo.GivenName + " " +
authenticationResult.UserInfo.FamilyName;
// cache security tokens
session["id_token"] = authenticationResult.IdToken;
session["access_token"] = authenticationResult.AccessToken;
session["refresh_token"] = authenticationResult.RefreshToken;
}
开发者ID:CriticalPathTraining,项目名称:DSU365,代码行数:13,代码来源:CustomAuthenticationManager.cs
示例15: ApplicationTokenProvider
/// <summary>
/// Create an application token provider that can retrieve tokens for the given application from the given context, using the given audience
/// and credential.
/// See <see href="https://azure.microsoft.com/en-us/documentation/articles/active-directory-devquickstarts-dotnet/">Active Directory Quickstart for .Net</see>
/// for detailed instructions on creating an Azure Active Directory application.
/// </summary>
/// <param name="context">The authentication context to use when retrieving tokens.</param>
/// <param name="tokenAudience">The token audience to use when retrieving tokens.</param>
/// <param name="credential">The client credential for this application.</param>
/// <param name="authenticationResult">The token details provided when authenticating with the client credentials.</param>
public ApplicationTokenProvider(AuthenticationContext context, string tokenAudience, ClientCredential credential, AuthenticationResult authenticationResult)
{
if (credential == null)
{
throw new ArgumentNullException("credential");
}
if (authenticationResult == null)
{
throw new ArgumentNullException("authenticationResult");
}
Initialize(context, tokenAudience, credential.ClientId, new MemoryApplicationAuthenticationProvider(credential), authenticationResult, authenticationResult.ExpiresOn);
}
开发者ID:Ranjana1996,项目名称:autorest,代码行数:24,代码来源:ApplicationTokenProvider.cs
示例16: PostTokenRequest
protected override void PostTokenRequest(AuthenticationResult result)
{
base.PostTokenRequest(result);
this.UniqueId = (result.UserInfo == null) ? null : result.UserInfo.UniqueId;
this.DisplayableId = (result.UserInfo == null) ? null : result.UserInfo.DisplayableId;
if (result.Resource != null)
{
this.Resource = result.Resource;
Logger.Verbose(this.CallState, "Resource value in the token response was used for storing tokens in the cache");
}
// If resource is not passed as an argument and is not returned by STS either,
// we cannot store the token in the cache with null resource.
// TODO: Store refresh token though if STS supports MRRT.
this.StoreToCache = this.StoreToCache && (this.Resource != null);
}
开发者ID:ankurchoubeymsft,项目名称:azure-activedirectory-library-for-dotnet,代码行数:16,代码来源:AcquireTokenByAuthorizationCodeHandler.cs
示例17: PopulateCurrentUserInformation
//Once we have an AuthenticationResult, get user information.
private void PopulateCurrentUserInformation(AuthenticationResult result)
{
var rl = ResourceLoader.GetForCurrentView();
AuthenticationHelper._settings.Values["TenantId"] = result.TenantId;
AuthenticationHelper._settings.Values["LastAuthority"] = AuthenticationHelper._authenticationContext.Authority;
_displayName = result.UserInfo.GivenName;
_mailAddress = result.UserInfo.DisplayableId;
EmailAddressBox.Text = _mailAddress;
WelcomeText.Text = "Hi " + _displayName + ". " + rl.GetString("WelcomeMessage");
MailButton.IsEnabled = true;
EmailAddressBox.IsEnabled = true;
_userLoggedIn = true;
ProgressBar.Visibility = Visibility.Collapsed;
ConnectButton.Content = "disconnect";
}
开发者ID:JacobM366,项目名称:O365-Win-Connect,代码行数:18,代码来源:MainPage.xaml.cs
示例18: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
//Test for AuthenticationResult
if (Session["authResult"] != null)
{
//Get the authentication result from the session
authResult = (AuthenticationResult)Session["authResult"];
//Show Power BI Panel
signInStatus.Visible = true;
//Set user and token from authentication result
userLabel.Text = authResult.UserInfo.DisplayableId;
accessTokenTextbox.Text = authResult.AccessToken;
}
}
开发者ID:ChrisMBenson,项目名称:PowerBI-CSharp,代码行数:17,代码来源:Default.aspx.cs
示例19: AuthenticateAsync
public async Task<bool> AuthenticateAsync()
{
await GetConfigAsync();
// prompts the user for authentication
_AuthenticationResult = await _Authenticator.Authenticate(_TenantAuthority, _ResourceUri, _AzureAuthenticationClientId, _ReturnUri);
var accessToken = await GetTokenAsync();
// instantiate an ActiveDirectoryClient to query the Graph API
var activeDirectoryGraphApiClient = new ActiveDirectoryClient(
new Uri(new Uri(_ResourceUri), _AzureGraphApiClientId),
() => Task.FromResult<string>(accessToken)
);
return true;
}
开发者ID:XnainA,项目名称:app-crm,代码行数:17,代码来源:AuthenticationService.cs
示例20: TokenCacheItem
/// <summary>
/// Default constructor.
/// </summary>
internal TokenCacheItem(TokenCacheKey key, AuthenticationResult result)
{
this.Authority = key.Authority;
this.Resource = key.Resource;
this.ClientId = key.ClientId;
this.TokenSubjectType = key.TokenSubjectType;
this.UniqueId = key.UniqueId;
this.DisplayableId = key.DisplayableId;
this.TenantId = result.TenantId;
this.ExpiresOn = result.ExpiresOn;
this.AccessToken = result.AccessToken;
this.IdToken = result.IdToken;
if (result.UserInfo != null)
{
this.FamilyName = result.UserInfo.FamilyName;
this.GivenName = result.UserInfo.GivenName;
this.IdentityProvider = result.UserInfo.IdentityProvider;
}
}
开发者ID:varunpsr,项目名称:XamarinAzureAD,代码行数:23,代码来源:TokenCacheItem.cs
注:本文中的Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论