Remove hardcoded chain ID (#32)

Close #31
This commit is contained in:
Simon Bihel 2022-07-05 15:30:28 +01:00 committed by GitHub
parent 297f3c29cf
commit 63ecdae730
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 7 deletions

View File

@ -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)]

View File

@ -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())))