1
+ using Duende . IdentityServer . Models ;
2
+
3
+ namespace Duende . IdentityServer . Demo . Pages ;
4
+
5
+ public static class DemoServerUtilities
6
+ {
7
+ public static string HumanizeAllowedGrantTypes ( ICollection < string > grantTypes )
8
+ {
9
+ if ( grantTypes . SequenceEqual ( GrantTypes . Implicit ) )
10
+ return "implicit" ;
11
+
12
+ if ( grantTypes . SequenceEqual ( GrantTypes . ImplicitAndClientCredentials ) )
13
+ return "implicit and client credentials" ;
14
+
15
+ if ( grantTypes . SequenceEqual ( GrantTypes . Code ) )
16
+ return "authorization code" ;
17
+
18
+ if ( grantTypes . SequenceEqual ( GrantTypes . CodeAndClientCredentials ) )
19
+ return "authorization code and client credentials" ;
20
+
21
+ if ( grantTypes . SequenceEqual ( GrantTypes . Hybrid ) )
22
+ return "hybrid" ;
23
+
24
+ if ( grantTypes . SequenceEqual ( GrantTypes . HybridAndClientCredentials ) )
25
+ return "hybrid and client credentials" ;
26
+
27
+ if ( grantTypes . SequenceEqual ( GrantTypes . ClientCredentials ) )
28
+ return "client credentials" ;
29
+
30
+ if ( grantTypes . SequenceEqual ( GrantTypes . ResourceOwnerPassword ) )
31
+ return "resource owner password" ;
32
+
33
+ if ( grantTypes . SequenceEqual ( GrantTypes . ResourceOwnerPasswordAndClientCredentials ) )
34
+ return "resource owner password and client credentials" ;
35
+
36
+ if ( grantTypes . SequenceEqual ( GrantTypes . DeviceFlow ) )
37
+ return "device flow" ;
38
+
39
+ if ( grantTypes . SequenceEqual ( GrantTypes . Ciba ) )
40
+ return "ciba" ;
41
+
42
+ return string . Join ( " " , grantTypes ) ;
43
+ }
44
+
45
+ public static string HumanizeLifetime ( TimeSpan lifetime )
46
+ {
47
+ var components = new List < string > ( ) ;
48
+ if ( lifetime . TotalHours > 0 )
49
+ {
50
+ components . Add ( Math . Floor ( lifetime . TotalHours ) + "h" ) ;
51
+ }
52
+ if ( Math . Floor ( lifetime . TotalMinutes % 60 ) > 0 )
53
+ {
54
+ components . Add ( Math . Floor ( lifetime . TotalMinutes % 60 ) + "m" ) ;
55
+ }
56
+ if ( Math . Floor ( lifetime . TotalSeconds % 60 ) > 0 )
57
+ {
58
+ components . Add ( Math . Floor ( lifetime . TotalSeconds % 60 ) + "s" ) ;
59
+ }
60
+
61
+ return string . Join ( " " , components ) ;
62
+ }
63
+
64
+ public static string ? HumanizeClientIdPrefix ( string clientIdPrefix ) =>
65
+ clientIdPrefix switch
66
+ {
67
+ "m2m" => "Machine-to-Machine" ,
68
+ "interactive" => "Interactive clients" ,
69
+ "native" => "Native clients" ,
70
+ "device" => "Device flow" ,
71
+ "login" => "Login" ,
72
+ _ => clientIdPrefix
73
+ } ;
74
+ }
0 commit comments