Skip to content

OAuth ​

Type
Class
Namespace
craft\services
Inherits
craft\services\OAuth » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable

Shared OAuth authorization and resource authentication.

@since 5.12.0

View source

Public Properties ​

PropertyDescription
behaviors\yii\base\Behavior<static>[] – List of behaviors attached to this component.
resourcesarray<string,resource>

resources ​

Type
array<string,resource>
Default value
null
Access
Read-only

View source

Public Methods ​

MethodDescription
__call()Calls the named method which is not a class method.
__clone()This method is called after the object is created by cloning an existing one.
__construct()Constructor.
__get()Returns the value of a component property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets the value of a component property.
__unset()Sets a component property to be null.
approveScopes()Narrows an authorization request to the access level the user chose, falling back to the narrowest level they may choose.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
authenticate()Authenticates a resource's bearer token and requires every supplied scope.
authorizedUser()
behaviors()Returns a list of behaviors that this component should behave as.
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
className()Returns the fully qualified name of this class.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.
generateKeys()Generate the default keys explicitly, without replacing existing keys.
getBehavior()Returns the named behavior object.
getBehaviors()Returns all behaviors attached to this component.
getResource()
getResources()
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined for this component.
init()Initializes the object.
issuer()
metadata()
off()Detaches an existing event handler from this component.
on()Attaches an event handler to an event.
protectedResourceMetadata()
resource()
resourceMetadataUrl()
resourceServer()
reuseConsent()Whether the user already approved the request's scopes for its client. If so, narrows the request to the access level they chose before.
server()
trigger()Triggers an event.
url()Returns the URL to an OAuth endpoint for the current request.

approveScopes() ​

Narrows an authorization request to the access level the user chose, falling back to the narrowest level they may choose.

View source

Arguments ​

  • $request
  • $resource
  • $user
  • $level

authenticate() ​

Authenticates a resource's bearer token and requires every supplied scope.

View source

Arguments ​

  • $request
  • $resource
  • $requiredScopes (string[])
  • $scopes (array, null) – Set to the scope IDs the token grants.

authorizedUser() ​

View source

Arguments ​

  • $id
  • $resource

generateKeys() ​

Generate the default keys explicitly, without replacing existing keys.

View source

Arguments ​

  • $force

getResource() ​

View source

Arguments ​

  • $id

getResources() ​

View source

Returns ​

array<string,resource>

issuer() ​

View source

Arguments ​

  • $resource

metadata() ​

View source

Arguments ​

  • $resource

protectedResourceMetadata() ​

View source

Arguments ​

  • $resource

resource() ​

View source

Arguments ​

  • $resource

resourceMetadataUrl() ​

View source

Arguments ​

  • $resource

resourceServer() ​

View source

Arguments ​

  • $resource

reuseConsent() ​

Whether the user already approved the request's scopes for its client. If so, narrows the request to the access level they chose before.

View source

Arguments ​

  • $request
  • $resource

server() ​

View source

Arguments ​

  • $resource

url() ​

Returns the URL to an OAuth endpoint for the current request.

Front-end requests get a site action URL, so the authorization flow can stay on the front end. Discovery metadata and the issuer always use the control panel URLs, so they don’t vary by request.

View source

Arguments ​

Returns ​

string

Constants ​

ConstantDescription
PERSONAL_ACCESS_PROVIDERThe user provider Craft 6’s Passport guard uses, which Passport matches personal access clients against.

Events ​

EVENT_REGISTER_RESOURCES ​

Type
craft\events\RegisterOAuthResourcesEvent

Registers protected API definitions.