17

Google OpenID プロバイダーで卓球をしているときに、フレンドリ名/ニックネーム/ユーザー名 (呼び方は何でも) を取得できません。

次のようなひどいものを取得します。

www.google.com/accounts/o8/id?id=AItOawmtAnQvSXGhRTkAHZWyxi4L4EKa7xoTT1dk  

のような素敵なものの代わりに

JohnDoe

たとえば、myopenid のように、Google からユーザーの名前を親しみやすい方法で取得するためのプロトコルは何ですか?

**DotNetOpenAuth を使用しています*

4

3 に答える 3

13

できません。OP が発行する識別子は、厳密には OP 次第です。RP には特に発言権はありません。現在、一部の OP は、ニックネーム、電子メール アドレスなど、ログインで属性を提供することをサポートしています。Google はこれらの属性を非常に限定的にサポートしており、電子メール アドレスのみを提供しています。

Google は、情報漏えいのリスクがあるため、ユーザーが認識できる識別子を発行しないことにしました。Yahoo は、ユーザーが選択できる、人間に優しい識別子と人間に優しくない識別子の両方をユーザーに提供することで、両方の道を行きました。MyOpenID やその他の OP は、通常、ユーザーが OP にサインアップするときに選択する使いやすい識別子のみを使用します。

RP で Google を特別なケースにして、ユーザーがログインしたときに表示するよりわかりやすい文字列を選択することもできます。または、これを行うのは Google だけではないため、識別子がいつ使用されるかを判断するコードを記述します。ユーザーがログインしていることを認識できるように、判読できず、ユーザーにとってわかりやすいものを表示します (おそらく、ユーザーの電子メール アドレスまたはサイトで選択したニックネーム)。

注意: Google が発行する識別子よりもわかりやすい識別子を表示することを選択した場合でも、渡すユーザーの正式なユーザー名とデータベースでのユーザー名の検索には、Googleの公式の Claimed Identifier を使用する必要がありFormsAuthentication.RedirectFromLoginます。それ以外のものを組み合わせると、通常、セキュリティ リスクが生じます。

于 2009-08-31T00:45:20.007 に答える
10

ロイの回答に基づいて、同じリクエストを使用しようとしましたが、DotNetOpenAuthうまくいきました。 リクエスト:

var req = openid.CreateRequest("https://www.google.com/accounts/o8/id");
var fetch = new FetchRequest();
fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Contact.Email,true));
fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Name.First,true));
fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Name.Last,true));

req.AddExtension(fetch);

注:AttributeRequestコンストラクターの 2 番目のパラメーターが true に設定されていることを確認してください。

応答部分は簡単です。

var openid = new OpenIdRelyingParty();
var response = openid.GetResponse();
var fetch = response.GetExtension<FetchResponse>();
if (fetch != null) {
IList<string> emailAddresses =fetch.Attributes[WellKnownAttributes.Contact.Email].Values;
IList<string> firstNames = fetch.Attributes[WellKnownAttributes.Name.First].Values;
IList<string> lastName = fetch.Attributes[WellKnownAttributes.Name.Last].Values;
}
于 2012-04-27T16:21:23.037 に答える
6

2012 年現在、Google OpenID エンドポイントは、Attribute Exchange プロトコルを介した姓名の取得をサポートしているようです。以下は、 Pyramid Web フレームワークと Janrain のpython-openidパッケージを使用した Python コードの例です。

from openid.consumer import consumer
from openid.extensions.ax import AttrInfo, FetchRequest, FetchResponse
from openid.store.filestore import FileOpenIDStore
from openid.store.sqlstore import PostgreSQLStore, MySQLStore, SQLiteStore

AX_FIRSTNAME = 'http://axschema.org/namePerson/first'
AX_LASTNAME = 'http://axschema.org/namePerson/last'
AX_EMAIL = 'http://axschema.org/contact/email'

@view_config(route_name='openID_start', permission=NO_PERMISSION_REQUIRED)
def start(request):
    'Start openID authentication process'
    params = request.params
    openIDURL = params.get('openIDURL')
    if not openIDURL:
        return HTTPResponse('Parameter expected: openIDURL')
    openIDConsumer = get_consumer(request)
    try:
        openIDRequest = openIDConsumer.begin(openIDURL)
    except consumer.DiscoveryFailure, error:
        return HTTPResponse('Discovery failed: %s' % escape(error))
    else:
        if not openIDRequest:
            return HTTPResponse('Not an openID provider: %s' % escape(openIDURL))

        axRequest = FetchRequest()
        axRequest.add(AttrInfo(AX_FIRSTNAME, required=True))
        axRequest.add(AttrInfo(AX_LASTNAME, required=True))
        axRequest.add(AttrInfo(AX_EMAIL, required=True))
        openIDRequest.addExtension(axRequest)

        sourceURL = request.host_url
        targetURL = request.route_url('openID_finish')
        if openIDRequest.shouldSendRedirect():
            return HTTPFound(location=openIDRequest.redirectURL(sourceURL, targetURL))
        return HTTPResponse(openIDRequest.htmlMarkup(sourceURL, targetURL))

@view_config(route_name='openID_finish', permission=NO_PERMISSION_REQUIRED)
def finish(request):
    'Finish openID authentication process'
    openIDConsumer = get_consumer(request)
    targetURL = request.route_url('openID_finish')
    openIDResponse = openIDConsumer.complete(request.params, targetURL)
    html = openIDResponse.status + '<br>'
    for key, value in openIDResponse.__dict__.iteritems():
        html += '%s: %s<br>' % (escape(key), escape(value))
    html += '<br>'
    if consumer.SUCCESS == openIDResponse.status:
        axResponse = FetchResponse.fromSuccessResponse(openIDResponse)
        html += 'First name: %s<br>' % escape(axResponse.get(AX_FIRSTNAME))
        html += 'Last name: %s<br>' % escape(axResponse.get(AX_LASTNAME))
        html += 'Email: %s<br>' % escape(axResponse.get(AX_EMAIL))
    return HTTPResponse(html)

def get_consumer(request):
    try:
        openIDStore = {
            'sqlite': SQLiteStore,
            'postgresql': PostgreSQLStore,
            'mysql': MySQLStore,
        }[db.bind.name](db.bind.raw_connection())
    except KeyError:
        openIDStore = FileOpenIDStore('data/openIDs')
    try:
        openIDStore.createTables()
    except:
        pass
    return consumer.Consumer(request.session, openIDStore)
于 2012-02-02T18:42:13.010 に答える