pub fn generate_sha256_challenge_and_verifier(&mut self) -> Result<(), GraphFailure> {
        let mut buf = [0; 32];
        let rng = ring::rand::SystemRandom::new();
        rng.fill(&mut buf)?;
        let verifier = base64::encode_config(&buf, base64::URL_SAFE_NO_PAD);
        let mut context = ring::digest::Context::new(&ring::digest::SHA256);
        context.update(&verifier.as_bytes());
        let code_challenge =
            base64::encode_config(context.finish().as_ref(), base64::URL_SAFE_NO_PAD);
        self.code_verifier(&verifier);
        self.code_challenge(&code_challenge);
        self.code_challenge_method("S256");
        Ok(())
    }
/// Generate a code challenge and code verifier for the
/// authorization code grant flow using proof key for
/// code exchange (PKCE) and SHA256.
///
/// This method automatically sets the code_verifier,
/// code_challenge, and code_challenge_method fields.
///
/// For authorization, the code_challenge_method parameter in the request body
/// is automatically set to 'S256'.
///
/// Internally this method uses the Rust ring cyrpto library to
/// generate a secure random 32-octet sequence that is base64 URL
/// encoded (no padding). This sequence is hashed using SHA256 and
/// base64 URL encoded (no padding) resulting in a 43-octet URL safe string.
///
///
/// For more info on PKCE and entropy see: https://tools.ietf.org/html/rfc7636#section-7.1
///
/// # Example
/// ```
/// # use graph_oauth::oauth::OAuth;
/// # use graph_oauth::oauth::OAuthCredential;
///
/// let mut oauth = OAuth::new();
/// oauth.generate_sha256_challenge_and_verifier();
///
/// # assert!(oauth.contains(OAuthCredential::CodeChallenge));
/// # assert!(oauth.contains(OAuthCredential::CodeVerifier));
/// # assert!(oauth.contains(OAuthCredential::CodeChallengeMethod));
/// println!("Code Challenge: {:#?}", oauth.get(OAuthCredential::CodeChallenge));
/// println!("Code Verifier: {:#?}", oauth.get(OAuthCredential::CodeVerifier));
/// println!("Code Challenge Method: {:#?}", oauth.get(OAuthCredential::CodeChallengeMethod));
///
/// # let challenge = oauth.get(OAuthCredential::CodeChallenge).unwrap();
/// # let mut context = ring::digest::Context::new(&ring::digest::SHA256);
/// # context.update(oauth.get(OAuthCredential::CodeVerifier).unwrap().as_bytes());
/// # let verifier = base64::encode_config(context.finish().as_ref(), base64::URL_SAFE_NO_PAD);
/// # assert_eq!(challenge, verifier);
/// ```
Generate a code challenge and code verifier for the
authorization code grant flow using proof key for
code exchange (PKCE) and SHA256.

This method automatically sets the code_verifier,
code_challenge, and code_challenge_method fields.

For authorization, the code_challenge_method parameter in the request body
is automatically set to 'S256'.

Internally this method uses the Rust ring cyrpto library to
generate a secure random 32-octet sequence that is base64 URL
encoded (no padding). This sequence is hashed using SHA256 and
base64 URL encoded (no padding) resulting in a 43-octet URL safe string.


Generate a code challenge and code verifier for the authorization code grant flow using proof key for code exchange ( PKCE ) and SHA256 . This method automatically sets the code_verifier code_challenge and code_challenge_method fields . For authorization the code_challenge_method parameter in the request body is automatically set to ' S256 ' . Internally this method uses the Rust ring cyrpto library to generate a secure random 32 - octet sequence that is base64 URL encoded ( no padding ) . This sequence is hashed using SHA256 and base64 URL encoded ( no padding ) resulting in a 43 - octet URL safe string .
pub fn generate_sha256_challenge_and_verifier(&mut self) -> Result<(), GraphFailure> {
        let mut buf = [0; 32];
        let rng = ring::rand::SystemRandom::new();
        rng.fill(&mut buf)?;
        let verifier = base64::encode_config(&buf, base64::URL_SAFE_NO_PAD);
        let mut context = ring::digest::Context::new(&ring::digest::SHA256);
        context.update(&verifier.as_bytes());
        let code_challenge =
            base64::encode_config(context.finish().as_ref(), base64::URL_SAFE_NO_PAD);
        self.code_verifier(&verifier);
        self.code_challenge(&code_challenge);
        self.code_challenge_method("S256");
        Ok(())
    }
pub fn generate_sha256_challenge_and_verifier ( & mut self ) -> Result < ( ) , GraphFailure > { let mut buf = [ 0 ; 32 ] ; let rng = ring :: rand :: SystemRandom :: new ( ) ; rng . fill ( & mut buf ) ? ; let verifier = base64 :: encode_config ( & buf , base64 :: URL_SAFE_NO_PAD ) ; let mut context = ring :: digest :: Context :: new ( & ring :: digest :: SHA256 ) ; context . update ( & verifier . as_bytes ( ) ) ; let code_challenge = base64 :: encode_config ( context . finish ( ) . as_ref ( ) , base64 :: URL_SAFE_NO_PAD ) ; self . code_verifier ( & verifier ) ; self . code_challenge ( & code_challenge ) ; self . code_challenge_method ( " " ) ; Ok ( ( ) ) }
Generate a code challenge and code verifier for the
authorization code grant flow using proof key for
code exchange (PKCE) and SHA256.
Generate a code challenge and code verifier for the authorization code grant flow using proof key for code exchange ( PKCE ) and SHA256 .
&mut self
&mut self
example
None
use graph_oauth::oauth::oauth;
None
use graph_oauth::oauth::oauthcredential;
let mut oauth = OAuth::new();
oauth.generate_sha256_challenge_and_verifier().
let mut oauth = OAuth :: new () ; oauth . generate_sha256_challenge_and_verifier () .
assert!(oauth.contains(oauthcredential::codechallenge));
None
assert!(oauth.contains(oauthcredential::codeverifier));
None
assert!(oauth.contains(oauthcredential::codechallengemethod));
println!("Code Challenge: {:#?}", oauth.get(OAuthCredential::CodeChallenge));
println!("Code Verifier: {:#?}", oauth.get(OAuthCredential::CodeVerifier));
println!("Code Challenge Method: {:#?}", oauth.get(OAuthCredential::CodeChallengeMethod)).
println! ( " Code Challenge : { : #? } " oauth . get ( OAuthCredential :: CodeChallenge )) ; println! ( " Code Verifier : { : #? } " oauth . get ( OAuthCredential :: CodeVerifier )) ; println! ( " Code Challenge Method : { : #? } " oauth . get ( OAuthCredential :: CodeChallengeMethod )) .
let challenge = oauth.get(oauthcredential::codechallenge).unwrap();
None
let mut context = ring::digest::context::new(&ring::digest::sha256);
None
context.update(oauth.get(oauthcredential::codeverifier).unwrap().as_bytes());
None
let verifier = base64::encode_config(context.finish().as_ref(), base64::url_safe_no_pad);
None
assert_eq!(challenge, verifier);
None