Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpBearerAuth with preflight request #8134

Closed
myc0210 opened this issue Apr 20, 2015 · 9 comments
Closed

HttpBearerAuth with preflight request #8134

myc0210 opened this issue Apr 20, 2015 · 9 comments

Comments

@myc0210
Copy link

myc0210 commented Apr 20, 2015

Is there any proper way to get rid of preflight OPTION request when i add authorization in http request. Now my work around is by making a component which extends HttpBearerAuth class and override authenticate function adding following line before the original code

if($request->getIsOptions()) {
    return true;
}

This works but i want to know whether there is a simple and correct way to handle this...

@klimov-paul
Copy link
Member

Add 'options' to except, when attaching filter:

public function behaviors()
{
    return [
        'bearerAuth' => [
            'class' => \yii\filters\auth\HttpBearerAuth::className(),
            'except' => ['options']
        ],
    ];
}

@yujin1st
Copy link

yujin1st commented Nov 6, 2017

This doesn't work as OPTION is type of request, that browser sends on the same url as original request

@cebe
Copy link
Member

cebe commented Nov 6, 2017

@yujin1st
Copy link

yujin1st commented Nov 9, 2017

Yes, i've done exactly as in documentation. "Except" skips only action ids in \yii\base\ActionFilter
2017-11-09 18 42 52

@cebe
Copy link
Member

cebe commented Nov 13, 2017

I meant the order of Authentication and Cors filter. Cors must be before Auth to handle the OPTIONS request.

@yujin1st
Copy link

Order is correct, but Cors filter doesn't send back response immediately, authentication is checked anyway.

@cebe
Copy link
Member

cebe commented Nov 14, 2017

@yujin1st you need an action that handles the options request then, which is excluded from auth. That is what @klimov-paul propsed.

@yujin1st
Copy link

yujin1st commented Nov 14, 2017

It seems i misunderstand processes:
As i digging into \yii\rest\ActiveController, i see it has an predefined action yii\rest\OptionsAction for such request, and it works fine, but i can't understand where OPTION request for any actions transforms into 'option' action?

How should i do such thing for my own rest controller (not activeController)?

@cebe
Copy link
Member

cebe commented Nov 14, 2017

This is done in yii\rest\UrlRule. See http://www.yiiframework.com/doc-2.0/guide-rest-routing.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants