parent
297f3c29cf
commit
63ecdae730
@ -27,6 +27,7 @@ pub struct CodeEntry {
|
||||
pub nonce: Option<Nonce>,
|
||||
pub client_id: String,
|
||||
pub auth_time: DateTime<Utc>,
|
||||
pub chain_id: Option<u64>, // TODO temporary, for transition purposes
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
|
27
src/oidc.rs
27
src/oidc.rs
@ -197,8 +197,14 @@ async fn resolve_avatar(_eth_provider: Option<Url>, _address: H160) -> Option<Ur
|
||||
async fn resolve_claims(
|
||||
eth_provider: Option<Url>,
|
||||
address: H160,
|
||||
chain_id: u64,
|
||||
) -> StandardClaims<CoreGenderClaim> {
|
||||
StandardClaims::new(subject_id(&address))
|
||||
let subject_id = SubjectIdentifier::new(format!(
|
||||
"eip155:{}:{}",
|
||||
chain_id,
|
||||
to_checksum(&address, None)
|
||||
));
|
||||
StandardClaims::new(subject_id)
|
||||
.set_preferred_username(Some(EndUserUsername::new(
|
||||
resolve_name(eth_provider.clone(), address).await,
|
||||
)))
|
||||
@ -217,10 +223,6 @@ pub struct TokenForm {
|
||||
pub grant_type: CoreGrantType, // TODO should just be authorization_code apparently?
|
||||
}
|
||||
|
||||
fn subject_id(address: &H160) -> SubjectIdentifier {
|
||||
SubjectIdentifier::new(format!("eip155:1:{}", to_checksum(address, None)))
|
||||
}
|
||||
|
||||
pub async fn token(
|
||||
form: TokenForm,
|
||||
// From the request's Authorization header
|
||||
@ -282,7 +284,12 @@ pub async fn token(
|
||||
vec![Audience::new(client_id.clone())],
|
||||
Utc::now() + Duration::seconds(60),
|
||||
Utc::now(),
|
||||
resolve_claims(eth_provider, code_entry.address).await,
|
||||
resolve_claims(
|
||||
eth_provider,
|
||||
code_entry.address,
|
||||
code_entry.chain_id.unwrap_or(1),
|
||||
)
|
||||
.await,
|
||||
EmptyAdditionalClaims {},
|
||||
)
|
||||
.set_nonce(code_entry.nonce)
|
||||
@ -585,6 +592,7 @@ pub async fn sign_in(
|
||||
exchange_count: 0,
|
||||
client_id: params.client_id.clone(),
|
||||
auth_time: Utc::now(),
|
||||
chain_id: Some(siwe_cookie.message.chain_id),
|
||||
};
|
||||
|
||||
let mut new_session_entry = session_entry.clone();
|
||||
@ -745,7 +753,12 @@ pub async fn userinfo(
|
||||
};
|
||||
|
||||
let response = CoreUserInfoClaims::new(
|
||||
resolve_claims(eth_provider, code_entry.address).await,
|
||||
resolve_claims(
|
||||
eth_provider,
|
||||
code_entry.address,
|
||||
code_entry.chain_id.unwrap_or(1),
|
||||
)
|
||||
.await,
|
||||
EmptyAdditionalClaims::default(),
|
||||
)
|
||||
.set_issuer(Some(IssuerUrl::from_url(base_url.clone())))
|
||||
|
Loading…
Reference in New Issue
Block a user