-
Notifications
You must be signed in to change notification settings - Fork 87
/
oauthcodes.html
127 lines (117 loc) · 4.02 KB
/
oauthcodes.html
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
<div class="oauthcodes">
<h3>OAuth Codes</h3>
<div class="panel panel-default">
<div class="panel-heading">Issued to me</div>
<div class="panel-body">
<div class="alert alert-info">Codes that can be used by this user to access resources on other servers</div>
<div class="noAcquired ih">There are no acquired codes yet</div>
<table class="table outCodesTable">
<thead>
<tr>
<th>Application</th>
<th>Actions<th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">Issued by me</div>
<div class="panel-body">
<div class="alert alert-info">Codes that other servers can use to access resources (such as projects, internal services etc...) on this server owned by the current user</div>
<div class="noIssued ih">There are no issued codes yet</div>
<table class="table issuedCodesTable">
<thead>
<tr>
<th></th>
<th>Application name</th>
<th>Issued on</th>
<th>Authorization</th>
<th>Actions<th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
<script>
function OAuthCodes(cd) {
var o = this;
this.revokeClick = function(){
var oid = $(this).parents("tr").attr("oid");
Global.bimServerApi.call("OAuthInterface", "revokeAuthorization", {oid: oid}, function(){
o.load();
});
};
this.load = function(){
Global.bimServerApi.call("OAuthInterface", "listAuthorizationCodes", {}, function(codes){
cd.find(".outCodesTable").toggle(codes.length != 0);
cd.find(".noAcquired").toggle(codes.length == 0);
cd.find(".outCodesTable tbody tr").remove();
codes.forEach(function(code){
var serverId = code.oauthServerId;
var tr = $("<tr>");
tr.attr("oid", code.oid);
Global.bimServerApi.call("OAuthInterface", "getOAuthServerById", {oid: serverId}, function(server){
tr.append("<td>" + server.registrationEndpoint + "</td>");
});
tr.append("<td>" + code.code + "</td>");
cd.find(".outCodesTable tbody").append(tr);
var td = $("<td>");
var revokeLink = $("<a>revoke</a>");
revokeLink.click(o.revokeClick);
td.append(revokeLink);
tr.append(td);
});
});
Global.bimServerApi.call("OAuthInterface", "listIssuedAuthorizationCodes", {}, function(codes){
cd.find(".issuedCodesTable").toggle(codes.length != 0);
cd.find(".noIssued").toggle(codes.length == 0);
cd.find(".issuedCodesTable tbody tr").remove();
codes.forEach(function(code){
var serverId = code.oauthServerId;
var tr = $("<tr>");
tr.attr("oid", code.oid);
cd.find(".issuedCodesTable tbody").append(tr);
var authorizationTd = $("<td>");
var clientNameTd = $("<td>");
var iconTd = $("<td>");
tr.append(iconTd);
tr.append(clientNameTd);
tr.append("<td>" + formatDateTime(new Date(code.issued)) + "</td>");
tr.append(authorizationTd);
Global.bimServerApi.call("OAuthInterface", "getOAuthServerById", {oid: code.oauthServerId}, function(server){
var icon = $("<img>");
icon.attr("src", "data:image/png;base64, " + server.clientIcon);
iconTd.append(icon);
clientNameTd.append(server.clientName);
});
var td = $("<td>");
var revokeLink = $("<a>revoke</a>");
revokeLink.click(o.revokeClick);
td.append(revokeLink);
tr.append(td);
Global.bimServerApi.call("OAuthInterface", "getAuthorizationById", {oid: code.authorizationId}, function(authorization){
if (authorization.__type == "SSingleProjectAuthorization") {
authorizationTd.append("Single Project Authorization (" + authorization.projectId + ")");
} else if (authorization.__type == "SRunServiceAuthorization") {
authorizationTd.append("Run Service Authorization");
Global.bimServerApi.call("PluginInterface", "getInternalServiceById", {
oid: authorization.serviceId
}, (service) => {
authorizationTd.append(" (" + service.name + ")");
});
} else {
console.log(authorization);
}
});
});
});
};
this.load();
this.show = function(){};
this.close = function(){};
}
</script>