Hot answers tagged

7

Install Magento from github.com/magento/magento2.git and then use the steps from documentation page about Token-based authentication On Github, you should look on branch '2.2.0-preview' or 'develop' or any other that uses the codebase of 2.2.0 or higher (develop is active branch by default). This feature probably will be backported on Magento 2.1.9 and ...


5

Please try this: Step 1: Get a bearer token: You can get a token by executing the signup mutation in the playground to create a new user. This is the signup mutation I ran: Request: mutation { generateCustomerToken(email: "customer@example.com", password: "password") { token } } Response: { "data": { "generateCustomerToken": { ...


3

Add this dependency to your class constructor: private $quoteIdMaskFactory; public function __construct( .... \Magento\Quote\Model\QuoteIdMaskFactory $quoteIdMaskFactory, .... ) { .... $this->quoteIdMaskFactory = $quoteIdMaskFactory; .... } Then your can retrieve the cart it like this: $maskedId = '696EreQdYt2AAtEceQsHfD2gxGyWFodG'; $...


2

You can use POST /V1/integration/admin/token API get bearer token for admin as mention in devdocs here. But you'll need admin username and password which cannot be programatically fetched (well admin username can be from session, but not password). So, you would have to make a dialogue asking for username and password and then you can generate bearer and ...


2

The resulting token should be used in subsequent requests in the Authorization header as a Bearer token ex: Authorization: Bearer {{resultFromGenerateCustomerToken}} I don't think ChromeQL allows the setting request Headers. If you are on OSX you can use this electron app which give you access to set the headers. https://github.com/skevy/graphiql-app ...


2

This is how Magento itself does it: // This line create a new token : $newPasswordToken = $this->mathRandom->getUniqueHash(); // Get the secure data from the customer $customerSecure = $this->customerRegistry->retrieveSecureData($customer->getId()); // Those lines update the rp_token and rp_token_created_at $customerSecure->setRpToken($...


2

Had the same question while reading Magento User Guide when first saw this button. And here is the answer from the guide: "Revokes the OAuth access tokens that are associated with the customer account. This can be used only with customer accounts that have been assigned OAuth tokens as part of a Web API integration. To learn more, see: OAuth-based ...


1

Fixed it by including these comments over the function in the interface: /** * GET for wishlist api * @param string $customerId * @return string */


1

Try below code, this works for me:- $request = new SoapClient("http://localhost/magento2sample/soap/?wsdl&services=integrationAdminTokenServiceV1"); $token = $request->integrationAdminTokenServiceV1CreateAdminAccessToken(array("username"=>"XXX", "password"=>"XXX")); $opts = array( 'http'=>array( '...


1

For customer token if you want it store wise then you need to pass store_code in the API url POST <host>/rest/<store_code>/V1/integration/customer/token But if you haven't configure any stores then pass default POST <host>/rest/default/V1/integration/customer/token And to fetch all store data using API storeStoreRepositoryV1 Group ...


1

Instead of using /rest/all/V1/integration/customer/token use this endpoint /rest/V1/integration/customer/token and you will get token.


1

Magento has talked about all environment variables in the link whichever you have shared. I hope, you want to save the API token and fetch it on controller to trigger web service call right. If so, you can create simple store configuration option in your module system.xml file which will allow store admin to set the token whenever you want and you can ...


1

The user api needs to have a role with permissions to access that resource. As a debug method though, I would first try to var_dump($token) to make sure you are first getting the token.


1

You're much likely to encounter a bug on core. A solution suggested by the user on github is clear the DB table oauth_token_request_log. You may have a try. Source: https://github.com/magento/magento2/issues/4432#issuecomment-258114623


1

webapi.xml <route url="/V1/test/most/" method="GET"> <service class="Vendor\Module\Api\TestRepositoryInterface" method="getTest"/> <resources> <resource ref="self"/> </resources> <data> <parameter name="customerId" force="true">%customer_id%</parameter> </data> &...


1

Get Admin Token Please check your URL action [It must be POST] magento.host/index.php/rest/V1/integration/customer/token?admin&password=admin123 it will generate admin token. The above case i explained is working fine for webAPI in magento2 which i tested in POSTMAN.


1

There are two types of authentication available in magento 2. One is via admin another is via customer. You can use below api to get the authenticated token which will be used to run all api having ref="self". {base_url}/rest/V1/integration/customer/token {base_url}/rest/V1/integration/admin/token Your request will be of POST type and param will be { "...


1

Right now you are able to access only that api which can be accessed anonymously. Now you are accessing a api which need a authentication key/access token to assure that you are a registered customer who is accessing such api's. So for generating you have to generate a access token using below api : {base_url}/rest/V1/integration/customer/token this is a ...


1

You have to add this line to your code curl_setopt($ch, CURLOPT_SSL_VERIFYPEER , false); like this $adminUrl='https://www.xxxxxxx.com/rest/V1/integration/admin/token'; $ch = curl_init(); $data = array("username" => "myusername, "password" => "mypassword"); $data_string = json_encode($data); $ch = curl_init($adminUrl); curl_setopt($ch, ...


1

I found that the problem was I was attempting to use a callback URL that required basic authentication. I did not notice this when I tested the URL because my computer had already authenticated. I changed the callback URL to a valid URL that did not require authentication and everything now works as expected.


1

Call this Library > \Magento\Braintree\Model\Adapter\BraintreeAdapterFactory $bt_adapter in construct. afterwards, $bt_adapter = $this->bt_factory->create(); $value = $bt_adapter->generate(); That should generate a client token for you provided that you first made the config in admin for Braintree


1

PHP Examples from dev doc magento-1 Create a simple product as an Admin user with OAuth authentication <?php /** * Example of simple product POST using Admin account via Magento REST API. OAuth authorization is used */ $callbackUrl = "http://yourhost/oauth_admin.php"; $temporaryCredentialsRequestUrl = "http://magentohost/oauth/initiate?oauth_callback=" ....


1

You cannot find the token and token secret from Magento backend. You need to query these from the database directly. First login to Magento backend and go to System->Web Services->REST - Oauth Consumers. Take a note of the oauth consumer you need the keys for. You can also find consumer_key and consumer_secret from there if you click on that consumer's row. ...


1

First create token from Admin->System->integrations then use below code. $ch = curl_init("http://your_domain.com/index.php/rest/V1/customers/search?searchCriteria"); $token = 'your_token'; curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/...


1

Magento provides API to work with payment tokens. The PaymentTokenManagementInterface contains a list of methods to retrieve tokens: getListByCustomerId getByPaymentId getByGatewayToken getByPublicHash The stored token can be used for to perform payment operations (see Braintree sale): \Braintree\Transaction::sale([ 'paymentMethodToken' => 'your ...


Only top voted, non community-wiki answers of a minimum length are eligible