1// Copyright 2023 The Matrix.org Foundation C.I.C.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
1415use std::time::Duration;
1617use ruma::{
18 api::client::account::request_openid_token, authentication::TokenType, OwnedServerName,
19};
20use serde::{Deserialize, Serialize};
2122#[derive(Clone, Debug, Deserialize, Serialize)]
23pub(crate) struct OpenIdState {
24pub(crate) original_request_id: String,
25pub(crate) access_token: String,
26#[serde(with = "ruma::serde::duration::secs")]
27pub(crate) expires_in: Duration,
28pub(crate) matrix_server_name: OwnedServerName,
29pub(crate) token_type: TokenType,
30}
3132impl OpenIdState {
33pub(crate) fn new(id: String, ruma: request_openid_token::v3::Response) -> Self {
34Self {
35 original_request_id: id,
36 access_token: ruma.access_token,
37 expires_in: ruma.expires_in,
38 matrix_server_name: ruma.matrix_server_name,
39 token_type: ruma.token_type,
40 }
41 }
42}
4344#[derive(Clone, Debug, Deserialize, Serialize)]
45#[serde(rename_all = "lowercase")]
46#[serde(tag = "state")]
47pub(crate) enum OpenIdResponse {
48 Allowed(OpenIdState),
49 Blocked {
50 original_request_id: String,
51 },
52#[serde(rename = "request")]
53Pending,
54}