Repository navigation
Expand file tree
/
Copy pathTransaction.cs
More file actions
62 lines (53 loc) · 1.95 KB
/
Copy pathTransaction.cs
File metadata and controls
62 lines (53 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Xml.Linq;
namespace Microsoft.AspNetCore.Authentication
{
public class Transaction
{
public HttpRequestMessage Request { get; set; }
public HttpResponseMessage Response { get; set; }
public IList<string> SetCookie { get; set; }
public string ResponseText { get; set; }
public XElement ResponseElement { get; set; }
public string AuthenticationCookieValue
{
get
{
if (SetCookie != null && SetCookie.Count > 0)
{
var authCookie = SetCookie.SingleOrDefault(c => c.Contains(".AspNetCore." + TestExtensions.CookieAuthenticationScheme + "="));
if (authCookie != null)
{
return authCookie.Substring(0, authCookie.IndexOf(';'));
}
}
return null;
}
}
public string FindClaimValue(string claimType, string issuer = null)
{
var claim = ResponseElement.Elements("claim")
.SingleOrDefault(elt => elt.Attribute("type").Value == claimType &&
(issuer == null || elt.Attribute("issuer").Value == issuer));
if (claim == null)
{
return null;
}
return claim.Attribute("value").Value;
}
public string FindTokenValue(string name)
{
var claim = ResponseElement.Elements("token")
.SingleOrDefault(elt => elt.Attribute("name").Value == name);
if (claim == null)
{
return null;
}
return claim.Attribute("value").Value;
}
}
}