-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move OAuth scopes into separate crate
- Loading branch information
1 parent
34d95fa
commit d5e6bec
Showing
16 changed files
with
242 additions
and
262 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "tf-scopes" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
pub const SCOPES: &[&str] = &[ | ||
Activity::READ, | ||
Activity::WRITE, | ||
Gear::READ, | ||
Gear::WRITE, | ||
User::READ, | ||
User::WRITE, | ||
]; | ||
|
||
pub trait Resource { | ||
const READ: &'static str; | ||
const WRITE: &'static str; | ||
} | ||
|
||
pub struct Activity; | ||
pub struct Gear; | ||
pub struct User; | ||
|
||
impl Resource for Activity { | ||
const READ: &'static str = "activity:read"; | ||
const WRITE: &'static str = "activity:write"; | ||
} | ||
|
||
impl Resource for Gear { | ||
const READ: &'static str = "gear:read"; | ||
const WRITE: &'static str = "gear:write"; | ||
} | ||
|
||
impl Resource for User { | ||
const READ: &'static str = "user:read"; | ||
const WRITE: &'static str = "user:write"; | ||
} | ||
|
||
enum Scopes { | ||
ActivityRead, | ||
ActivityWrite, | ||
GearRead, | ||
GearWrite, | ||
UserRead, | ||
UserWrite, | ||
} | ||
|
||
impl std::str::FromStr for Scopes { | ||
type Err = (); | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
Ok(match s { | ||
Activity::READ => Self::ActivityRead, | ||
Activity::WRITE => Self::ActivityWrite, | ||
Gear::READ => Self::GearRead, | ||
Gear::WRITE => Self::GearWrite, | ||
User::READ => Self::UserRead, | ||
User::WRITE => Self::UserWrite, | ||
_ => return Err(()), | ||
}) | ||
} | ||
} | ||
|
||
pub struct Read<S>(pub S); | ||
pub struct Write<S>(pub S); | ||
|
||
pub trait Scope { | ||
const SCOPE: &'static str; | ||
} | ||
|
||
impl Scope for () { | ||
const SCOPE: &'static str = ""; | ||
} | ||
|
||
impl<S: Resource> Scope for Read<S> { | ||
const SCOPE: &'static str = S::READ; | ||
} | ||
|
||
impl<S: Resource> Scope for Write<S> { | ||
const SCOPE: &'static str = S::WRITE; | ||
} |