pub enum Scope {
TextEncoded(TextEncodedScope),
BinaryEncoded(BinaryEncodedScope),
AifEncoded(AifEncodedScope),
LibdcafEncoded(LibdcafEncodedScope),
}
Expand description
Scope of an access token as specified in RFC 9200, section 5.8.1.
May be used both for AccessTokenRequests and AccessTokenResponses. Note that you rarely need to create instances of this type for that purpose, instead you can just pass in the concrete types (e.g. TextEncodedScope, BinaryEncodedScope) directly into the builder.
Example
You can create binary, AIF-, or text-encoded scopes:
let text_scope = Scope::from(TextEncodedScope::try_from("dcaf rs")?);
let binary_scope = Scope::from(BinaryEncodedScope::try_from(vec![0xDC, 0xAF].as_slice())?);
let aif_scope = Scope::from(AifEncodedScope::from(vec![("/tmp", AifRestMethod::Get.into())]));
For information on how to initialize a specific scope type or retrieve the individual elements inside them, see their respective documentation pages.
Variants§
TextEncoded(TextEncodedScope)
Scope encoded using Text, as specified in RFC 6749, section 1.3.
For details, see the documentation of TextEncodedScope
.
Example
Creating a scope containing “device_alpha” and “device_beta” (note that spaces in their name wouldn’t work):
let scope = TextEncodedScope::try_from(vec!["device_alpha", "device_beta"])?;
assert_eq!(scope, TextEncodedScope::try_from("device_alpha device_beta")?);
assert!(scope.elements().eq(vec!["device_alpha", "device_beta"]));
assert!(TextEncodedScope::try_from(vec!["device alpha", "device beta"]).is_err());
BinaryEncoded(BinaryEncodedScope)
Scope encoded using custom binary encoding.
For details, see the documentation of BinaryEncodedScope
.
Example
Creating a scope containing 0xDCAF and 0xAFDC with a separator of 0x00:
let scope = BinaryEncodedScope::try_from(vec![0xDC, 0xAF, 0x00, 0xAF, 0xDC].as_slice())?;
assert!(scope.elements(Some(0x00))?.eq(&vec![vec![0xDC, 0xAF], vec![0xAF, 0xDC]]));
assert!(scope.elements(None)?.eq(&vec![vec![0xDC, 0xAF, 0x00, 0xAF, 0xDC]]));
assert!(scope.elements(Some(0xDC)).is_err()); // no separators at the beginning or end
AifEncoded(AifEncodedScope)
Scope encoded using the Authorization Information Format (AIF) for ACE.
For details, see the documentation of AifEncodedScope
.
Example
Creating a scope containing ["/s/temp", 1]
(1 representing GET
) and ["/a/led", 5]
(5 representing GET
and FETCH
):
let scope = AifEncodedScope::from(vec![
("/s/temp", AifRestMethod::Get.into()),
("/a/led", AifRestMethod::Get | AifRestMethod::Fetch)
]);
LibdcafEncoded(LibdcafEncodedScope)
libdcaf
-specific
variant of AifEncoded
which consists of only a single
AifEncodedScopeElement
.
Use only if trying to maintain compatibility to libdcaf
.
For details, see the documentation of LibdcafEncodedScope
.
Example
Creating a scope containing ["/s/temp", 1]
(1 representing GET
):
let scope = LibdcafEncodedScope::new("/s/temp", AifRestMethod::Get.into());