2

I'm looking for a tutorial/example/explanation about writing a two-legged provider for OAuth in Django.

It's hard to find documentation about a OAuth provider, and even harder about a two-legged system...

4

3 に答える 3

6

私はこれを理解しようとして約3日を費やし、クエリしようとしていたサービスから最終的に得たこの実用的な例を使用できる人に提供したいと考えました. それは非常に簡単になりました。PS 誰かが oauth 1.0 を使用しているからといって、oauth2 ライブラリを使用できないわけではありません。

auth2 を取得するには、pip install oauth2 と入力します。

スクリプトには、次のものが必要です。

import oauth2
import time
import urllib2


def build_request(url, method='GET'):
    params = {                                            
        'oauth_version': "1.0",
        'oauth_nonce': oauth2.generate_nonce(),
        'oauth_timestamp': int(time.time())
    }
    consumer = oauth2.Consumer(key='python_test',secret='your_secret')
    params['oauth_consumer_key'] = consumer.key

    req = oauth2.Request(method=method, url=url, parameters=params)
    signature_method = oauth2.SignatureMethod_HMAC_SHA1()
    req.sign_request(signature_method, consumer, None)
    return req

関数を呼び出して出力を表示すると、次のようになります。

request = build_request('http://demo.echo360.com/ess/scheduleapi/v1/terms')
u = urllib2.urlopen(request.to_url())
print u.readlines()
于 2012-10-03T14:15:13.993 に答える
1

「2 レッグ」は、アクセス トークンまたはアクセス トークン シークレットのない通常の OAuth 要求です。それでおしまい。クライアント資格情報 (識別子とシークレット) を引き続き使用しますが、アクセス トークン パラメーターには空の文字列を使用します。使用するサーバー ライブラリによっては、リクエストを行うときに oauth_token パラメータを省略できます。

于 2011-08-02T16:02:59.830 に答える
1

これは良い開始記事です: http://philipsoutham.com/post/2172924723/two-legged-oauth-in-python

Piston の Two-legged OAuth: https://github.com/gregbayer/django-piston-two-legged-oauth

于 2012-01-29T19:54:11.340 に答える