OAuth and redirect_uri in offline Python script
<p>I'm currently trying to write a Python script that will use Deviantart's API to automatically shuffle my favourites. To do that I need to first log in in my script. Deviantart uses OAuth2 authentication, which requires a redirect_uri, which as I understand it is supposed to be the server where my application is running.</p>

<p>However I'm running the script locally on my computer (not on a server) and just sending http requests via Python's <code>Requests</code> library. How do I then authenticate, when the OAuth procedure sends the code required for the authentication token as a parameter of a <code>GET</code> call to the redirect_uri, which points to nowhere in particular for me? Is there no way to authenticate without running a server?</p>

<h2>EDIT</h2>

<p>My problem is still that I'm running a simple offline script, and I'm not sure how to authenticate from it.</p>

<p>This is my authentication code so far:</p>

<pre><code>import binascii, os, requests

def auth():
    request = 'https://www.deviantart.com/oauth2/authorize'
    state = binascii.hexlify(os.urandom(160))
    params = {
        'response_type': 'token',
        'client_id': 1,
        'redirect_uri': 'https://localhost:8080',
        'state': state,
        'scope': 'user'
    }
    r = requests.get(request, params)
    print(r)
</code></pre>

<p>The printed response is simply a 200 HTTP code, rather than an access token (obviously, since the username and password haven't been entered anywhere). The request is sent to DA's authorisation page, but since the page itself doesn't actually open in my script, I can't enter my username and password to log in anywhere. And I can't directly send the username and password in the <code>GET</code> request to authenticate that way either (again obviously, since it would be a terrible idea to send the password like that).</p>

<p>Preferably I'd like a way to simply have the user (me) prompted for the username and password in the console that the script is running in and then have the script continue executing after the user has successfully logged in.</p>

<p>Alternatively, if the above is not possible, the script should open the authorisation webpage in a browser, and then continue execution once the user logs in. </p>

<p>How would I go about realising either of these two solutions in Python?</p>

<p>You are supposed to get authorization token using received code. This token will be used to access DeviantArt afterwards. </p>

<p>Refer to <a href="https://www.deviantart.com/developers/authentication" rel="nofollow">https://www.deviantart.com/developers/authentication</a> (section "Using The Authorization Code Grant").</p>

python oauth oauth-2.0 deviantart-api