Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication #1

Closed
FeodorFitsner opened this issue Mar 24, 2022 · 4 comments
Closed

Authentication #1

FeodorFitsner opened this issue Mar 24, 2022 · 4 comments
Labels
enhancement Improvement/Optimization

Comments

@FeodorFitsner
Copy link
Contributor

FeodorFitsner commented Mar 24, 2022

Useful materials:

Configuring OAuth provider:

provider = GitHubOAuthProvider(
  "<client_id>",
  "<client_secret>",
  "<redirect_url>",
  ["user", "public_repo])

Authenticate (start OAuth flow) user:

auth: Authentication = page.login(provider, fetch_user=True, fetch_groups=True)
# fetch_users, fetch_groups if enabled ensure required scopes are set
page.auth # the last Authentication
page.auth.token # authentication token
page.auth.user # instance of AuthUser class
page.auth.provider # instance of OAuthProvider

Check if a session is authenticated:

if page.auth != None:
  # user is logged in
class OAuthProvider():
  _name
  client_id
  client_secret
  authorization_endpoint
  token_endpoint
  redirect_url
  def get_user():
    pass
class OAuthToken():
  token
  created
  expiresIn
  refreshToken
  scope
  token_type
class AuthUser():
  id
class GitHubUser(AuthUser):
  full_name
  email
  teams

Providers

GitHub

  • authorization_endpoint: https://github.com/login/oauth/authorize
  • token_endpoint: https://github.com/login/oauth/access_token
  • User scope: read:user, user:email
  • Groups scope: read:org
  • Get emails
  • Get user
  • Get teams

Google

  • authorization_endpoint: https://accounts.google.com/o/oauth2/auth
  • token_endpoint: https://oauth2.googleapis.com/token
  • User scope: https://www.googleapis.com/auth/userinfo.email, https://www.googleapis.com/auth/userinfo.profile
  • Groups scope: ?
  • Get user: https://www.googleapis.com/oauth2/v3/userinfo
    • sub
    • email
    • name

Azure

Redirect URLs

Web: http(s)://{application_url}/api/oauth/redirect
Desktop: http://localhost/api/oauth/redirect
Mobile: flet://api/oauth/redirect

login(provider) method flow

  • Generate random state value, save state in Authentication object.
  • Build authorization URL with redirect_url.
  • Call page.oauth_login(authorization_url, state).
  • Fletd stores an expiring cache object under oauth_state_{state} key and page_id:session_id value.
  • Fletd calls oauth_login on a client with authorization_url and state.
  • Flet client opens authorization_url in:
  • After user login and consent on OAuth provider side:
    • Web and desktop:
      • Redirects back to redirect_url.
      • Fletd fetches page_id:session_id by oauth_state_{state} key. Verifies state.
      • Fletd sends on_authorize event to a Python code with code, error, state.
      • Fletd generates HTML output with JavaScript code closing browser window/tab.
    • Mobile:
      • Verifies state.
      • Flet client sends on_authorize event to a Python code with code, error, state.
  • On Python side internal on_authorize handler called:
    • Validate state
    • Request token with code, client_secret, token_endpoint.
  • user and groups optionally fetch.
  • page.on_login event handler called.
@FeodorFitsner FeodorFitsner added the enhancement Improvement/Optimization label Jun 12, 2022
@jet10000
Copy link

jet10000 commented Jul 2, 2022

cool

@dhayford92
Copy link

I will like to contribute to the projects

@ObiajuluM
Copy link

is this live, I'm really looking forward to using it

@FeodorFitsner
Copy link
Contributor Author

It's coming next week.

@FeodorFitsner FeodorFitsner added the status: working on it Working on a fix for the issue label Sep 28, 2022
@FeodorFitsner FeodorFitsner removed the status: working on it Working on a fix for the issue label Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement/Optimization
Projects
None yet
Development

No branches or pull requests

4 participants