-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBriarRabbitController.cs
More file actions
133 lines (125 loc) · 5.03 KB
/
BriarRabbitController.cs
File metadata and controls
133 lines (125 loc) · 5.03 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using TokenExchange.Contracts;
using TokenExchange.Contracts.Models;
using TokenExchange.Contracts.Services;
using Utils.Models;
namespace BriarRabbitTokenExchange
{
[Route("api/token_exchange")]
[ApiController]
public class BriarRabbitController : ControllerBase
{
private readonly ILogger<BriarRabbitController> _logger;
public BriarRabbitController(
ILogger<BriarRabbitController> logger)
{
_logger = logger;
}
[HttpPost]
[Authorize]
[Route("briar_rabbit/pass-through-handler")]
public Task<List<TokenExchangeResponse>> PostPassThroughHandlerExchangeAsync(TokenExchangeRequest tokenExchangeRequest)
{
var result = new List<TokenExchangeResponse>(){
new TokenExchangeResponse()
{
accessToken = new AccessTokenResponse()
{
hint="briar_rabbit/pass-through-handler",
access_token = $"briar_rabbit_access_token_{Guid.NewGuid().ToString()}",
refresh_token = $"briar_rabbit_refresh_token_{Guid.NewGuid().ToString()}",
expires_in = 1234,
token_type = $"briar_rabbit_Type",
authority =$"https://briar.rabbit.com/authority",
HttpHeaders = new List<HttpHeader>
{
new HttpHeader()
{
Name = "x-bunnyAuthScheme",
Value = "BunnyAuthority"
}
}
}
}
};
return Task.FromResult(result);
}
[HttpPost]
[Authorize]
[Route("briar_rabbit/final-pipeline-exchange")]
public Task<List<ExternalExchangeTokenResponse>> PostFinalPipelineExchangeAsync(ExternalExchangeTokenExchangeHandler.TokenExchangeRequestPackage tokenExchangeRequest)
{
var result = new List<ExternalExchangeTokenResponse>()
{
new ExternalExchangeTokenResponse()
{
CustomTokenResponse = new CustomTokenResponse()
{
authority = Guid.NewGuid().ToString(),
hint = "briar_rabbit/token-exchange-validator/custom",
Type = Guid.NewGuid().ToString(),
Token = Guid.NewGuid().ToString(),
HttpHeaders = new List<HttpHeader>()
{
new HttpHeader()
{
Name = Guid.NewGuid().ToString(),
Value = Guid.NewGuid().ToString()
}
}
},
ArbitraryIdentityTokenRequest = new ArbitraryIdentityTokenRequest()
{
Hint = "briarRabbitHint_Identity",
IdentityTokenLifetime = 3600,
ArbitraryClaims = new Dictionary<string, List<string>>()
{
{ "role", new List<string>{ "bigFluffy","fluffyAdmin"} }
},
Scope = "briar",
Subject = "MrRabbit"
},
ArbitraryResourceOwnerTokenRequest = new ArbitraryResourceOwnerTokenRequest()
{
Hint = "briarRabbitHint_Access",
AccessTokenLifetime = 3600,
ArbitraryClaims = new Dictionary<string, List<string>>()
{
{ "role", new List<string>{ "bigFluffy","fluffyAdmin"} }
},
Scope = "offline_access graphQLPlay",
Subject = "MrRabbit",
HttpHeaders = new List<HttpHeader>()
{
new HttpHeader()
{
Name = "x-bunnyAuthScheme",
Value = "BunnyAuthority"
}
}
}
}
};
return Task.FromResult(result);
}
// GET: api/SomeThing
[HttpGet]
[Route("testG")]
public IEnumerable<string> GetTest()
{
return new string[] { Guid.NewGuid().ToString() };
}
// POST: api/SomeThing
[HttpPost]
[Route("test")]
public IEnumerable<string> PostTest([FromBody] string value)
{
return new string[] { $"{value}.{Guid.NewGuid().ToString()}" };
}
}
}