Struct ShopifyApp

Source
pub struct ShopifyApp {
    pub access_mode: AccessMode,
    pub auth_callback_url: String,
    pub credentials: Credentials,
    pub host: String,
    pub scopes: Vec<&'static str>,
}

Fields§

§access_mode: AccessMode§auth_callback_url: String§credentials: Credentials§host: String§scopes: Vec<&'static str>

Implementations§

Source§

impl ShopifyApp

This is an implementation of the ShopifyApp struct.

§Examples

use shopify_app::ShopifyApp;

let app = ShopifyApp::new(); let nonce = app.new_nonce(); let auth_uri = app.new_auth_uri(“my-shop.myshopify.com”, “http://localhost:3000/auth”, &nonce); This method generates a new nonce value as a string.

A nonce (number used once) is a random value that is used to protect against replay attacks in authentication systems. This method uses the TextNonce type from the ring crate to generate a cryptographically secure random value and converts it into a string. The string is then modified by replacing plus signs with hyphens and forward slashes with underscores.

§Examples

use shopify_app::ShopifyApp;

let app = ShopifyApp::new(); let nonce = app.new_nonce(); This method generates a new authorization URI for the Shopify OAuth authentication flow.

The method takes a shop domain string &str, a return URI string &str, and a nonce string &str as arguments and returns a String. The shop argument should be the domain of the Shopify shop that the application is being installed on, the return_uri argument should be the URI that the user’s browser should be redirected to after authentication, and the nonce argument should be a nonce value to protect against replay attacks.

The method uses the api_key and scopes fields of the credentials field of the ShopifyApp struct, and the access_mode field of the struct, to construct the authorization URI using a format string. The URI is then returned.

§Examples

use shopify_app::ShopifyApp;

let app = ShopifyApp::new(); let nonce = app.new_nonce(); let auth_uri = app.new_auth_uri(“my-shop.myshopify.com”, “http://localhost:3000/auth”, &nonce);

Source

pub fn new_nonce() -> String

Source

pub fn new_auth_uri(&self, shop: &str, return_uri: &str, nonce: &str) -> String

Source§

impl ShopifyApp

Source

pub fn generate_hmac_bytes( &self, data: &[u8], ) -> GenericArray<u8, <Hmac<Sha256> as Mac>::OutputSize>

This method generates a HMAC (keyed-hash message authentication code) of the data passed as an argument as a byte array.

The method takes a slice of bytes &[u8] as an argument and returns a type that implements the GenericArray trait from the generic-array crate, with the element type u8 and the size specified by the OutputSize associated type of the HmacSha256 type from the hmac crate.

The method uses the HmacSha256 type to create a new variable-length HMAC using the HmacSha256::new_varkey method, passing in the secret field of the credentials field of the ShopifyApp struct as a byte slice. The expect method is called on the result to unwrap the Result type that new_varkey returns, which will panic if the key is invalid.

Source

pub fn generate_hmac_hex(&self, data: &[u8]) -> String

Source

pub fn generate_hmac_base64(&self, data: &[u8]) -> String

Source

pub fn valid_hmac(&self, query_params: &Vec<(String, String)>) -> bool

Source§

impl ShopifyApp

Source

pub fn shopify_url(shop: &str) -> bool

This method checks whether the given shop domain string is a valid Shopify shop domain.

The method takes a shop domain string &str as an argument and returns a bool.

Source§

impl ShopifyApp

Source

pub fn validate_auth( &self, query_params: &Vec<(String, String)>, validate_hmac: bool, ) -> Result<(String, String), Error>

Source

pub fn validate_auth_callback( &self, nonce: &str, query_params: &Vec<(String, String)>, ) -> Result<(), Error>

Trait Implementations§

Source§

impl Clone for ShopifyApp

Source§

fn clone(&self) -> ShopifyApp

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V