Authentication (OAuth 1.0a)
magento-1Fluxo 3-legged OAuth 1.0a, códigos de erro e configuração de consumers.
/oauth/initiate
OAuth 1.0a — Authentication flow
Nota (PT-BR): a REST API usa OAuth 1.0a (3-legged). Os três passos abaixo são obrigatórios.
OAuth Authentication
Magento uses OAuth 1.0a — a token-passing mechanism that allows users to control which applications have access to their data without revealing their passwords.
Key Definitions
- User — the Magento user (admin or customer) granting access
- Consumer — the third-party application
- Consumer Key / Consumer Secret — identify the consumer
- Request Token — temporary credential used to request access
- Access Token — long-lived credential granted after authorization
OAuth Process — three steps
- POST
/oauth/initiate— get an unauthorized Request Token. - GET
/oauth/authorize(customer) or/admin/oauth_authorize(admin) — user authorization. - POST
/oauth/token— exchange Request Token for Access Token.
Authorization Header
Every REST request must include:
oauth_consumer_keyoauth_nonceoauth_signature_method(HMAC-SHA1,RSA-SHA1orPLAINTEXT)oauth_signatureoauth_timestampoauth_tokenoauth_version
OAuth Error Codes
- 1 / 400 — version_rejected
- 2 / 400 — parameter_absent
- 3 / 400 — parameter_rejected
- 4 / 401 — timestamp_refused
- 5 / 401 — nonce_used
- 6 / 400 — signature_method_rejected
- 7 / 401 — signature_invalid
- 8 / 401 — consumer_key_rejected
- 9 / 401 — consumer_key_unknown
- 10 / 401 — token_used
- 11 / 401 — token_expired
- 12 / 401 — token_revoked
- 13 / 401 — token_rejected
Exemplos de Código
/admin/oauth/configure
OAuth Configuration (Admin Panel)
OAuth Configuration
Working with Consumers
- System > Web Services > REST - OAuth Consumers.
- Click Add New and fill in
Name,Callback URLandRejected Callback URL. KeyandSecretare auto-generated and cannot be edited.
Token Management (Admin)
- View authorized tokens at System > Web Services > REST - OAuth Authorized Tokens.
- Mass actions: enable, revoke, delete.
Token Management (Frontend)
Customers manage their apps at My Account > My Applications.
Cleanup Configuration
Set the probability threshold and expiration period (minutes) for temporary token cleanup at System > Configuration > Services > OAuth.