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

Skeleton OAuth implementation #55

Merged
merged 3 commits into from
Dec 11, 2024
Merged

Conversation

faisal-fawad
Copy link
Collaborator

Closes #54

A skeleton implementation of OAuth using Google as the provider; Key features:

  • Login persistence using Flask helper library
  • A User class which implements the required properties and methods + additional features
    • find_or_create_user primarily searches on the unique provider IDs and fallbacks to an email search
    • username will not be used for any authentication as it will be sent as a parameter and may be used maliciously by the user
  • Two endpoints for initiating the authorization process and handling the callback

username has not been implemented in this PR. A future PR will handle this containing the username parameter, extension on the User class, and an endpoint to validate username uniqueness

@faisal-fawad faisal-fawad linked an issue Nov 3, 2024 that may be closed by this pull request
Comment on lines +30 to +33
def get_clientside_data(self):
return {
"email": self.user_data.get("email"),
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this to get data that needs to be sent to front end

success = login_user(user)
if success:
user.authenticate_user()
return redirect(f'{current_app.config["BASE_URL"]}/?{urlencode(user.get_clientside_data())}')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the redirect here to include needed client-side data

@bp.route("/authorize/<provider>")
def user_authorize(provider):
if not current_user.is_anonymous:
return redirect(f'{current_app.config["BASE_URL"]}/?{urlencode(current_user.get_clientside_data())}')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed redirect here to include client-side data

@bp.route("/callback/<provider>")
def user_callback(provider):
if not current_user.is_anonymous:
return redirect(current_app.config["BASE_URL"])
Copy link
Collaborator

@zachale zachale Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@faisal-fawad do you think it would make sense to update this redirect like the others?
This would trigger if you accessed the callback endpoint but are already logged in right?
When could that happen?

}
}
BASE_URL = (
"https://playimaginate.com" if DB_ENV == "prod" else "http://localhost:5173"
Copy link
Collaborator

@zachale zachale Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the local host base url to the client localhost instead of the API localhost


def create_app():
app = Flask(__name__)
CORS(app)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added cors for ez testing. Does not matter when deployed. ( I think )

@zachale zachale merged commit eb560a4 into main Dec 11, 2024
3 checks passed
@zachale zachale deleted the 54-skeleton-oauth-implementation branch December 11, 2024 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Skeleton OAuth implementation
2 participants