7
7
use aide:: {
8
8
axum:: ApiRouter ,
9
9
openapi:: { OAuth2Flow , OAuth2Flows , OpenApi , SecurityScheme , Server , Tag } ,
10
+ transform:: TransformOpenApi ,
10
11
} ;
11
12
use axum:: {
12
13
extract:: { FromRef , FromRequestParts , State } ,
@@ -37,6 +38,72 @@ mod v1;
37
38
use self :: call_context:: CallContext ;
38
39
use crate :: passwords:: PasswordManager ;
39
40
41
+ fn finish ( t : TransformOpenApi ) -> TransformOpenApi {
42
+ t. title ( "Matrix Authentication Service admin API" )
43
+ . tag ( Tag {
44
+ name : "compat-session" . to_owned ( ) ,
45
+ description : Some ( "Manage compatibility sessions from legacy clients" . to_owned ( ) ) ,
46
+ ..Tag :: default ( )
47
+ } )
48
+ . tag ( Tag {
49
+ name : "oauth2-session" . to_owned ( ) ,
50
+ description : Some ( "Manage OAuth2 sessions" . to_owned ( ) ) ,
51
+ ..Tag :: default ( )
52
+ } )
53
+ . tag ( Tag {
54
+ name : "user" . to_owned ( ) ,
55
+ description : Some ( "Manage users" . to_owned ( ) ) ,
56
+ ..Tag :: default ( )
57
+ } )
58
+ . tag ( Tag {
59
+ name : "user-email" . to_owned ( ) ,
60
+ description : Some ( "Manage emails associated with users" . to_owned ( ) ) ,
61
+ ..Tag :: default ( )
62
+ } )
63
+ . tag ( Tag {
64
+ name : "user-session" . to_owned ( ) ,
65
+ description : Some ( "Manage browser sessions of users" . to_owned ( ) ) ,
66
+ ..Tag :: default ( )
67
+ } )
68
+ . tag ( Tag {
69
+ name : "upstream-oauth-link" . to_owned ( ) ,
70
+ description : Some (
71
+ "Manage links between local users and identities from upstream OAuth 2.0 providers"
72
+ . to_owned ( ) ,
73
+ ) ,
74
+ ..Default :: default ( )
75
+ } )
76
+ . security_scheme (
77
+ "oauth2" ,
78
+ SecurityScheme :: OAuth2 {
79
+ flows : OAuth2Flows {
80
+ client_credentials : Some ( OAuth2Flow :: ClientCredentials {
81
+ refresh_url : Some ( OAuth2TokenEndpoint :: PATH . to_owned ( ) ) ,
82
+ token_url : OAuth2TokenEndpoint :: PATH . to_owned ( ) ,
83
+ scopes : IndexMap :: from ( [ (
84
+ "urn:mas:admin" . to_owned ( ) ,
85
+ "Grant access to the admin API" . to_owned ( ) ,
86
+ ) ] ) ,
87
+ } ) ,
88
+ authorization_code : Some ( OAuth2Flow :: AuthorizationCode {
89
+ authorization_url : OAuth2AuthorizationEndpoint :: PATH . to_owned ( ) ,
90
+ refresh_url : Some ( OAuth2TokenEndpoint :: PATH . to_owned ( ) ) ,
91
+ token_url : OAuth2TokenEndpoint :: PATH . to_owned ( ) ,
92
+ scopes : IndexMap :: from ( [ (
93
+ "urn:mas:admin" . to_owned ( ) ,
94
+ "Grant access to the admin API" . to_owned ( ) ,
95
+ ) ] ) ,
96
+ } ) ,
97
+ implicit : None ,
98
+ password : None ,
99
+ } ,
100
+ description : None ,
101
+ extensions : IndexMap :: default ( ) ,
102
+ } ,
103
+ )
104
+ . security_requirement_scopes ( "oauth2" , [ "urn:mas:admin" ] )
105
+ }
106
+
40
107
pub fn router < S > ( ) -> ( OpenApi , Router < S > )
41
108
where
42
109
S : Clone + Send + Sync + ' static ,
@@ -58,65 +125,7 @@ where
58
125
let mut api = OpenApi :: default ( ) ;
59
126
let router = ApiRouter :: < S > :: new ( )
60
127
. nest ( "/api/admin/v1" , self :: v1:: router ( ) )
61
- . finish_api_with ( & mut api, |t| {
62
- t. title ( "Matrix Authentication Service admin API" )
63
- . tag ( Tag {
64
- name : "compat-session" . to_owned ( ) ,
65
- description : Some (
66
- "Manage compatibility sessions from legacy clients" . to_owned ( ) ,
67
- ) ,
68
- ..Tag :: default ( )
69
- } )
70
- . tag ( Tag {
71
- name : "oauth2-session" . to_owned ( ) ,
72
- description : Some ( "Manage OAuth2 sessions" . to_owned ( ) ) ,
73
- ..Tag :: default ( )
74
- } )
75
- . tag ( Tag {
76
- name : "user" . to_owned ( ) ,
77
- description : Some ( "Manage users" . to_owned ( ) ) ,
78
- ..Tag :: default ( )
79
- } )
80
- . tag ( Tag {
81
- name : "user-email" . to_owned ( ) ,
82
- description : Some ( "Manage emails associated with users" . to_owned ( ) ) ,
83
- ..Tag :: default ( )
84
- } )
85
- . tag ( Tag {
86
- name : "user-session" . to_owned ( ) ,
87
- description : Some ( "Manage browser sessions of users" . to_owned ( ) ) ,
88
- ..Tag :: default ( )
89
- } )
90
- . security_scheme (
91
- "oauth2" ,
92
- SecurityScheme :: OAuth2 {
93
- flows : OAuth2Flows {
94
- client_credentials : Some ( OAuth2Flow :: ClientCredentials {
95
- refresh_url : Some ( OAuth2TokenEndpoint :: PATH . to_owned ( ) ) ,
96
- token_url : OAuth2TokenEndpoint :: PATH . to_owned ( ) ,
97
- scopes : IndexMap :: from ( [ (
98
- "urn:mas:admin" . to_owned ( ) ,
99
- "Grant access to the admin API" . to_owned ( ) ,
100
- ) ] ) ,
101
- } ) ,
102
- authorization_code : Some ( OAuth2Flow :: AuthorizationCode {
103
- authorization_url : OAuth2AuthorizationEndpoint :: PATH . to_owned ( ) ,
104
- refresh_url : Some ( OAuth2TokenEndpoint :: PATH . to_owned ( ) ) ,
105
- token_url : OAuth2TokenEndpoint :: PATH . to_owned ( ) ,
106
- scopes : IndexMap :: from ( [ (
107
- "urn:mas:admin" . to_owned ( ) ,
108
- "Grant access to the admin API" . to_owned ( ) ,
109
- ) ] ) ,
110
- } ) ,
111
- implicit : None ,
112
- password : None ,
113
- } ,
114
- description : None ,
115
- extensions : IndexMap :: default ( ) ,
116
- } ,
117
- )
118
- . security_requirement_scopes ( "oauth2" , [ "urn:mas:admin" ] )
119
- } ) ;
128
+ . finish_api_with ( & mut api, finish) ;
120
129
121
130
let router = router
122
131
// Serve the OpenAPI spec as JSON
0 commit comments