OAuth2 Client Configuration

I’m trying to create a new auth client for Mailchimp. Here’s my configuration in common/config:




'authClientCollection' => [

            'class' => 'yii\authclient\Collection',

            'clients' => [

                'mailchimp' => [

                    'class' => 'common\authclient\Mailchimp',

                    'clientId' => '12345679',

                    'clientSecret' => 'abcdefghijklmni...',

                ],

            ],

        ],



And here’s my client class (so far):




<?php


namespace common\authclient;


use yii\authclient\OAuth2;


class Mailchimp extends OAuth2

{

	/**

     * {@inheritdoc}

     */

    public $authUrl = 'https://login.mailchimp.com/oauth2/authorize';


	/**

     * {@inheritdoc}

     */

    public $tokenUrl = 'https://login.mailchimp.com/oauth2/token';


    /**

     * {@inheritdoc}

     */

    public $apiBaseUrl = 'https://login.mailchimp.com/oauth2/';


     /**

     * @inheritdoc

     */

    protected function initUserAttributes()

    {

        return $this->api('userinfo', 'GET');

    }


    /**

     * {@inheritdoc}

     */

    protected function defaultName()

    {

        return 'MailChimp';

    }


    /**

     * {@inheritdoc}

     */

    protected function defaultTitle()

    {

        return 'MailChimp';

    }


}



When I do


use common\authclient\Mailchimp;

$oauthClient = new Mailchimp(); var_dump($oathClient);

I get this:


object(common\authclient\Mailchimp)#149 (23) {

  ["authUrl"]=>

  string(44) "https://login.mailchimp.com/oauth2/authorize"

  ["tokenUrl"]=>

  string(40) "https://login.mailchimp.com/oauth2/token"

  ["apiBaseUrl"]=>

  string(35) "https://login.mailchimp.com/oauth2/"

  ["version"]=>

  string(3) "2.0"

  ["clientId"]=>

  NULL

  ["clientSecret"]=>

  NULL

Why are the id and secret properties empty?

Do you use Php 7?

Yes. I’m not sure if it matters, but the server is running 5.5.9. The webspace is running 7.

Have a look at https://auth0.com/blog/migrating-a-php5-app-to-php7-part-two/ under "Closure on Call" section if can help you.

I’m fairly new to closures (outside of dabbling with them in JavaScript). After messing around a bit I’ve managed to do a closure of the entire controller class, including the auth manager and params. :slight_smile: So I see how this can work. It just needs some refinement. I’m not sure why I would need to use a closure. It’s not mentioned in the docs.