Auth
OAuth2
You can use this class to authenticate yourself or get URLs to redirect your users to and get them to give your Genius app the premissions you need. To find out more about how to use this class visit the Snippets.
- class lyricsgenius.auth.OAuth2(client_id, redirect_uri, client_secret=None, scope=None, state=None, client_only_app=False)
Genius OAuth2 authorization flow.
Using this class you can authenticate a user, and get their token.
- Parameters:
client_id (
str) – Client IDredirect_uri (
str) – Whitelisted redirect URI.client_secret (
str, optional) – Client secret.scope (
tuple|"all", optional) – Token privileges.state (
str, optional) – Request state.client_only_app (
bool, optional) – True to use the client-only authorization flow, otherwise False.
- Raises:
AssertionError – If neither
client_secret, norclient_only_appis supplied.
- property url
Returns the URL you redirect the user to.
You can use this property to get a URL that when opened on the user’s device, shows Genius’s authorization page where user clicks Agree to give your app access, and then Genius redirects user back to your redirect URI.
- get_user_token(code=None, url=None, state=None, **kwargs)
Gets a user token using the url or the code parameter..
If you supply value for
code, this method will use the value of thecodeparameter to request a token from Genius.If you use the :method`client_only_app` and supplt the redirected URL, it will already have the token. You could pass the URL to this method or parse it yourself.
If you provide a
statethe method will also compare it to the initial state and will raise an exception if they’re not equal.- Parameters:
code (
str) – ‘code’ parameter of redirected URL.url (
str) – Redirected URL (used in client-only apps)state (
str) – state parameter of redirected URL (only provide if you want to compare with initialself.state)**kwargs – keywords for the POST request.
- Returns:
User token.
- Return type:
str
- prompt_user()
Prompts current user for authentication.
Opens a web browser for you to log in with Genius. Prompts to paste the URL after logging in to parse the token URL parameter.
- Returns:
User token.
- Return type:
str
- classmethod client_only_app(client_id, redirect_uri, scope=None, state=None)
Returns an OAuth2 instance for a client-only app.
- Parameters:
client_id (
str) – Client ID.redirect_uri (
str) – Whitelisted redirect URI.scope (
tuple|"all", optional) – Token privilages.state (
str, optional) – Request state.
- Returns:
- classmethod full_code_exchange(client_id, redirect_uri, client_secret, scope=None, state=None)
Returns an OAuth2 instance for a full-code exchange app.
- Parameters:
client_id (
str) – Client ID.redirect_uri (
str) – Whitelisted redirect URI.client_secret (
str) – Client secret.scope (
tuple|"all", optional) – Token privilages.state (
str, optional) – Request state.
- Returns: