---
title: $pinc.oauth
slug: dollarpincoauth
docTags: 
createdAt: 2020-04-06T10:25:27.000Z
---

The pinc.oauth library gives you the ability to modify your user experiences by invoking event callbacks events.&#x20;

## Attach an event handler once the user consents

Attach an event handler to watch post user consent. This is a positive event and only fires if consented.

```javascript


//$pinc_onload is called by the pathfix library once the page base libraries are loaded
function $pinc_onload(){
    //watch if the user has consented
    $pinc.events.on("$pinc.oauth","consented",(data)=>{
        console.log(data);
    },true)
}
```

**Handler arguments (data)**

```json

{
    provider:"providername"
}
```

## Check if the user has previously consented an integration

The OAuth library allows you to check if the current user has already consented an integration. This is useful if you have a return user to your integration page and would like to alter the user experience base on whether your user has previously consented or not.

```javascript

	
function checkAuthorized(){
	var provider = "googlemail";
	var userId = "user@myapp.com"
	//set the userId to null and it will user the default provided in the data-user-id attribute
	$pinc.oauth.authorized(provider, userId, (authorized)=>{
		console.log(authorized);
	})
}
	
```

### Arguments

| provider | required | Internal name of the provider. Can be found here.                                                                                                      |
| -------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| userId   | optional | Your end user id. This defaults to the value specified in `data-user-id` attribute of the script element. The value if specified acts as an override.  |

### Callback Response

Boolean

