我对围绕OAuth的文献感到困惑和困惑。假设我们想要连接到OAuth提供商twitter。我们有mysite.com,它有各种各样的用户,其中一些还有一个推特账号。我是否需要为每个用户单独的消费者密钥和/或单独的消费者秘密,或者我是否只有 1对?
答案 0 :(得分:4)
消费者密钥和密钥对是特定于应用程序的,每个应用程序将是一个密钥/密钥对。应用程序可以是移动应用程序,网站,也可以只是隐藏在计算机上的脚本。例如,Twitter有针对Android的Twitter,针对iOS的Twitter和针对Mac的Twitter的不同消费者密钥/秘密。
每个用户必须专门授权每个应用程序(也称为消费者密钥/密钥对),并且将具有唯一标识用户已授权该特定消费者密钥的访问令牌和密钥对。
答案 1 :(得分:1)
是
请求令牌仅与消费者(Mysite)关联,直到特定用户授权它为止。
访问令牌知道消费者(Mysite)及其适用的用户。拥有它的人识别为Mysite并且可以代表该用户执行操作。
以下是oauth-php如何实现它:http://code.google.com/p/oauth-php/source/browse/trunk/library/store/mysql/mysql.sql
#
# ////////////////// SERVER SIDE /////////////////
#
# Table holding consumer key/secret combos an user issued to consumers.
# Used for verification of incoming requests.
CREATE TABLE IF NOT EXISTS oauth_server_registry (
osr_id int(11) not null auto_increment,
osr_usa_id_ref int(11),
osr_consumer_key varchar(64) binary not null,
osr_consumer_secret varchar(64) binary not null,
osr_enabled tinyint(1) not null default '1',
osr_status varchar(16) not null,
osr_requester_name varchar(64) not null,
osr_requester_email varchar(64) not null,
osr_callback_uri varchar(255) not null,
osr_application_uri varchar(255) not null,
osr_application_title varchar(80) not null,
osr_application_descr text not null,
osr_application_notes text not null,
osr_application_type varchar(20) not null,
osr_application_commercial tinyint(1) not null default '0',
osr_issue_date datetime not null,
osr_timestamp timestamp not null default current_timestamp,
primary key (osr_id),
unique key (osr_consumer_key),
key (osr_usa_id_ref)
# , foreign key (osr_usa_id_ref) references any_user_auth(usa_id_ref)
# on update cascade
# on delete set null
) engine=InnoDB default charset=utf8;
CREATE TABLE IF NOT EXISTS oauth_server_token (
ost_id int(11) not null auto_increment,
ost_osr_id_ref int(11) not null,
ost_usa_id_ref int(11) not null,
ost_token varchar(64) binary not null,
ost_token_secret varchar(64) binary not null,
ost_token_type enum('request','access'),
ost_authorized tinyint(1) not null default '0',
ost_referrer_host varchar(128) not null default '',
ost_token_ttl datetime not null default '9999-12-31',
ost_timestamp timestamp not null default current_timestamp,
ost_verifier char(10),
ost_callback_url varchar(512),
primary key (ost_id),
unique key (ost_token),
key (ost_osr_id_ref),
key (ost_token_ttl),
foreign key (ost_osr_id_ref) references oauth_server_registry (osr_id)
on update cascade
on delete cascade
# , foreign key (ost_usa_id_ref) references any_user_auth (usa_id_ref)
# on update cascade
# on delete cascade
) engine=InnoDB default charset=utf8;