use crate::generated::v1;
use crate::identity::{
AuthorizeRequest, AuthorizeResponse, GetGrantRequest, GetGrantResponse, GrantScope,
IntrospectRequest, IntrospectResponse, ListGrantsRequest, ListGrantsResponse,
RevokeGrantRequest, RevokeGrantResponse, TokenRequest, TokenResponse, UserInfoRequest,
UserInfoResponse,
};
pub(crate) fn to_wire_authorize_request(value: AuthorizeRequest) -> v1::AuthorizeRequest {
v1::AuthorizeRequest {
response_type: value.response_type,
client_id: value.client_id,
redirect_uri: value.redirect_uri,
scope: value.scope,
state: value.state,
}
}
pub(crate) fn from_wire_authorize_response(value: v1::AuthorizeResponse) -> AuthorizeResponse {
AuthorizeResponse {
redirect_uri: value.redirect_uri,
}
}
pub(crate) fn to_wire_get_grant_request(value: GetGrantRequest) -> v1::GetGrantRequest {
v1::GetGrantRequest {
grant_id: value.grant_id,
}
}
pub(crate) fn from_wire_get_grant_response(value: v1::GetGrantResponse) -> GetGrantResponse {
GetGrantResponse {
scopes: value
.scopes
.into_iter()
.map(from_wire_grant_scope)
.collect(),
created_at: value.created_at,
expires_at: value.expires_at,
}
}
pub(crate) fn from_wire_grant_scope(value: v1::GrantScope) -> GrantScope {
GrantScope {
scope: value.scope,
resource: value.resource,
}
}
pub(crate) fn to_wire_introspect_request(value: IntrospectRequest) -> v1::IntrospectRequest {
v1::IntrospectRequest {
token: value.token,
token_type_hint: value.token_type_hint,
}
}
pub(crate) fn from_wire_introspect_response(value: v1::IntrospectResponse) -> IntrospectResponse {
IntrospectResponse {
active: value.active,
subject: value.subject,
scope: value.scope,
client_id: value.client_id,
audience: value.audience,
}
}
pub(crate) fn to_wire_list_grants_request(_value: ListGrantsRequest) -> v1::ListGrantsRequest {
v1::ListGrantsRequest {}
}
pub(crate) fn from_wire_list_grants_response(value: v1::ListGrantsResponse) -> ListGrantsResponse {
ListGrantsResponse {
grant_ids: value.grant_ids,
}
}
pub(crate) fn to_wire_revoke_grant_request(value: RevokeGrantRequest) -> v1::RevokeGrantRequest {
v1::RevokeGrantRequest {
grant_id: value.grant_id,
}
}
pub(crate) fn from_wire_revoke_grant_response(
_value: v1::RevokeGrantResponse,
) -> RevokeGrantResponse {
RevokeGrantResponse {}
}
pub(crate) fn to_wire_token_request(value: TokenRequest) -> v1::TokenRequest {
v1::TokenRequest {
grant_type: value.grant_type,
code: value.code,
redirect_uri: value.redirect_uri,
client_id: value.client_id,
state: value.state,
scope: value.scope,
subject_token: value.subject_token,
subject_token_type: value.subject_token_type,
expires_in: value.expires_in,
}
}
pub(crate) fn from_wire_token_response(value: v1::TokenResponse) -> TokenResponse {
TokenResponse {
access_token: value.access_token,
token_type: value.token_type,
expires_in: value.expires_in,
refresh_token: value.refresh_token,
scope: value.scope,
grant_id: value.grant_id,
}
}
pub(crate) fn to_wire_user_info_request(_value: UserInfoRequest) -> v1::UserInfoRequest {
v1::UserInfoRequest {}
}
pub(crate) fn from_wire_user_info_response(value: v1::UserInfoResponse) -> UserInfoResponse {
UserInfoResponse {
subject_id: value.subject_id,
email: value.email,
name: value.name,
}
}