1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#[macro_use] extern crate rocket;
#[get("/")]
fn index() -> &'static str {
"Hello, World!"
}
#[rocket::main]
async fn main() -> Result<(), anyhow::Error> {
dotenv::dotenv().ok();
env_logger::init();
log::debug!("hello");
use openidconnect::core::{
CoreAuthenticationFlow, CoreClient, CoreProviderMetadata, CoreResponseType,
CoreUserInfoClaims,
};
use openidconnect::{
AccessTokenHash, AuthenticationFlow, AuthorizationCode, ClientId, ClientSecret, CsrfToken,
IssuerUrl, Nonce, PkceCodeChallenge, RedirectUrl, Scope,
};
use openidconnect::reqwest::async_http_client;
use openidconnect::url::Url;
// // Use OpenID Connect Discovery to fetch the provider metadata.
use openidconnect::{OAuth2TokenResponse, TokenResponse};
let provider_metadata = CoreProviderMetadata::discover_async(
IssuerUrl::new("https://auth.orbekk.com/realms/test".to_string())?,
async_http_client,
).await?;
let client =
CoreClient::from_provider_metadata(
provider_metadata,
ClientId::new("test-client".to_string()),
Some(ClientSecret::new("EbIMIpGnYPrG1GBl6eZtVM5zIhiuu5p1".to_string())),
)
// Set the URL the user will be redirected to after the authorization process.
.set_redirect_uri(RedirectUrl::new("https://bridge.orbekk.com/keycloak-callback".to_string())?);
let (auth_url, csrf_token, nonce) = client
.authorize_url(AuthenticationFlow::<CoreResponseType>::AuthorizationCode,
CsrfToken::new_random,
Nonce::new_random)
.add_scope(Scope::new("profile".to_string()))
.url();
log::info!("{:?}", auth_url);
rocket::build().mount("/", routes![index]).launch().await;
Ok(())
}
|