filsh / yii2-oauth2-server

A wrapper for implementing an OAuth2 Server(https://github.com/bshaffer/oauth2-server-php)
MIT License
332 stars 167 forks source link

Add support of CORS headers #9

Closed kirill-konshin closed 4 years ago

kirill-konshin commented 9 years ago

I had to override the DefaultController to add CORS behavior:

<?php

namespace app\controllers;

use app\extensions\Cors;
use filsh\yii2\oauth2server\controllers\DefaultController;
use yii;

class OauthController extends DefaultController
{

    public function init(){
        parent::init();
        $this->module = Yii::$app->getModule('oauth2');
    }

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return yii\helpers\ArrayHelper::merge(parent::behaviors(), [
            'corsFilter' => [
                'class' => Cors::className() // some custom config inside the class
            ],
        ]);
    }

    public function actionOptions()
    {

        Yii::$app->getResponse()->getHeaders()->set('Allow', implode(', ', ['OPTIONS', 'POST']));

    }

}

Without that each oauth request will fail because of no CORS headers

filsh commented 9 years ago

OK, I'll test it and make changes.

ebuzzz commented 9 years ago

+1 Any news on this issue?

mtangoo commented 9 years ago

43

nadeemse commented 8 years ago

Hi @kirill-konshin ,

I am unable to call OPTIONS request, can you please suggest me something because i am stuck on this point from a long time.

When i am calling URL to generate token i am getting this response.


{
  "name": "Method Not Allowed",
  "message": "The request method must be POST when requesting an access token",
  "code": 0,
  "status": 405,
  "type": "filsh\yii2\oauth2server\exceptions\HttpException"
}

Also if possible can you please share your CORS file so i can know what is inside of that file.

Your help will save my time.

kirill-konshin commented 8 years ago

I have provided all that I have in another topic: https://github.com/Filsh/yii2-oauth2-server/issues/8

danisetg commented 5 years ago

Hi, I know there have been like 4 years since this issue was post, but I am trying to implement this right now, and I'm still having problems with this.

danisetg commented 5 years ago

@kirill-konshin can you please tell me how did you finally solve it? I'm not actually using this, but the fork https://github.com/hosannahighertech/yii2-oauth2-server

kirill-konshin commented 5 years ago

The way I fixed it is in the description.

varp commented 4 years ago

@kirill-konshin @danisetg Could check if the problem still exist in the latest release - v2.1.0?

varp commented 4 years ago

Feel free to re-open. Closing due to inactivity.