Skip to main content

authorize_url

Function authorize_url 

Source
pub fn authorize_url(
    provider: &Provider,
    client_id: &str,
    redirect_uri: &str,
    state: &str,
    code_challenge: &str,
) -> String
Expand description

The URL to send the browser to: the provider’s sign-in page for this app.

redirect_uri must be registered with the provider exactly; state is a random value (crate::token::generate) kept in the session and compared on the callback (CSRF protection); code_challenge is Pkce::challenge.

§Examples

use ocre::oauth::{GOOGLE, authorize_url};

let url = authorize_url(&GOOGLE, "id", "http://localhost:8787/auth/google/callback", "st", "ch");
assert_eq!(
    url,
    "https://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id=id\
     &redirect_uri=http%3A%2F%2Flocalhost%3A8787%2Fauth%2Fgoogle%2Fcallback&scope=openid+email+profile\
     &state=st&code_challenge=ch&code_challenge_method=S256"
);