
Security News
Astral Launches pyx: A Python-Native Package Registry
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Yt::Auth lets you easily authenticate users of your website by means of their Google-based email address.
With Yt::Auth, it is easy to limit access to your app to a few users without the need for them to create a username and password.
The source code is available on GitHub and the documentation on RubyDoc.
With the url_for
class method, you can obtain a URL where to redirect users
who need to authenticate with their Google account in order to use your
application:
redirect_uri = 'https://example.com/auth' # REPLACE WITH REAL ONE
scope = %i(yt-analytics.readonly youtube)
Yt::Auth.url_for(redirect_uri: redirect_uri, scope: scope, force: true)
# => https://accounts.google.com/o/oauth2/auth?client_id=...&scope=email&redirect_uri=https%3A%2F%2Fexample.com%2Fauth&response_type=code
After users have authenticated with their Google account, they will be
redirected to the redirect_uri
you indicated, with an extra code
query
parameter, e.g. https://example.com/auth?code=1234
With the create
class method, you can create an instance for that
authentication:
redirect_uri = 'https://example.com/auth' # REPLACE WITH REAL ONE
code = 'dfwe7r9djd234ffdjf3009dfknfd98re' # REPLACE WITH REAL ONE
auth = Yt::Auth.create(redirect_uri: redirect_uri, code: code)
# => #<Yt::Auth:0x007fe61d…>
Once you have an instance of Yt::Auth
, you can obtain the verified email
of the authenticated user:
auth.email
# => "user@example.com"
Once you have an instance of Yt::Auth
, you can also obtain the access token
of the authenticated user:
auth.access_token
# => "ya29.df8er8e9r89er"
Once you have an instance of Yt::Auth
, you can also obtain the refresh token
of the authenticated user:
auth.refresh_token
# => "sdf7f7erre98df"
If you already know the refresh token of a Google account, you can obtain its complete authentication object:
auth = Auth.find_by(refresh_token: "sdf7f7erre98df")
auth.email
# => "user@example.com"
Yt::HTTPError
will be raised whenever something goes wrong during the
authentication process. The message of the error will include the details:
redirect_uri = 'https://example.com/auth' # REPLACE WITH REAL ONE
code = 'this-is-not-a-valid-code'
Yt::Auth.new(redirect_uri: redirect_uri, code: code).email
# => Yt::HTTPError: Invalid authorization code.
Contribute to the code by forking the project, adding the missing code, writing the appropriate tests and submitting a pull request.
To run the tests correctly, set up the environment variables YT_ACCOUNT_CLIENT_ID
and YT_ACCOUNT_CLIENT_SECRET
with the credentials of an existing Google OAuth app.
In order for a PR to be approved, all the tests need to pass and all the public methods need to be documented and listed in the guides. Remember:
bundle exec rspec
bundle exec yard
bundle exec yard stats --list-undoc
FAQs
Unknown package
We found that yt-auth demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.