Skip to content

Commit

Permalink
add addScopes
Browse files Browse the repository at this point in the history
  • Loading branch information
pilcrowonpaper committed Jun 29, 2024
1 parent fae2c5f commit f292061
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 182 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# @oslojs/oauth2

## 0.3.0

- [Breaking] Remove `setScopes()` and rename `appendScopes()` to `addScopes()`

## 0.2.0

- [Breaking] Remove APIs for sending requests
Expand Down
9 changes: 1 addition & 8 deletions docs/pages/examples/authorization-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,13 @@ const state = generateState();
const url = new AuthorizationCodeAuthorizationURL(authorizationEndpoint, clientId);
url.setRedirectURI("https://my-app.com/login/callback");
url.setState(state);
url.setScopes("user", "profile");
url.addScopes("user", "profile");

const redirectLocation = url.toString();

// Store state as cookie or in session.
```

Use `appendScopes()` to append new scopes to existing ones.

```ts
url.appendScopes("user");
url.appendScopes("profile");
```

## Validation authorization code

Create a new [`AuthorizationCodeTokenRequestContext`](/reference/main/AuthorizationCodeTokenRequestContext) and send a request to the token endpoint using the context's method, body (`application/x-www-form-urlencoded`), and headers.
Expand Down
9 changes: 1 addition & 8 deletions docs/pages/examples/device-authorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {

const context = new DeviceAuthorizationRequestContext();
context.authenticateWithHTTPBasicAuth(clientId, clientPassword);
context.setScopes("profile", "email");
context.addScopes("profile", "email");

const body = new URLSearchParams();
for (const [key, value] of context.body.entries()) {
Expand Down Expand Up @@ -54,13 +54,6 @@ context.authenticateWithRequestBody(clientId, clientSecret);
context.setClientId(clientId);
```

Use `appendScopes()` instead of `setScopes()` to append new scopes to existing ones.

```ts
url.appendScopes("user");
url.appendScopes("profile");
```

## Validate device code

Create a new [`DeviceAuthorizationTokenRequestContext`](/reference/main/DeviceAuthorizationTokenRequestContext) and send a request to the token endpoint using the context's method, body (`application/x-www-form-urlencoded`), and headers.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: "AuthorizationCodeAuthorizationURL.addScopes()"
---

# AuthorizationCodeAuthorizationURL.addScopes()

Appends scopes to the `scope` parameter.

## Definition

```ts
function addScopes(...scopes: string[]): void;
```

### Parameters

- `scopes`

## Example

```ts
url.addScopes("profile", "email");
url.addScopes("openid");
```

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ function constructor(authorizationEndpoint: string, clientId: string): this;

See also [`URL` methods](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams#instance_methods).

- [`appendScopes()`](/reference/main/AuthorizationCodeAuthorizationURL/appendScopes)
- [`addScopes()`](/reference/main/AuthorizationCodeAuthorizationURL/addScopes)
- [`setPlainCodeChallenge()`](/reference/main/AuthorizationCodeAuthorizationURL/setPlainCodeChallenge)
- [`setRedirectURI()`](/reference/main/AuthorizationCodeAuthorizationURL/setRedirectURI)
- [`setS256CodeChallenge()`](/reference/main/AuthorizationCodeAuthorizationURL/setS256CodeChallenge)
- [`setScopes()`](/reference/main/AuthorizationCodeAuthorizationURL/setScopes)
- [`setState()`](/reference/main/AuthorizationCodeAuthorizationURL/setState)

## Properties
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: "DeviceAuthorizationRequestContext.addScopes()"
---

# DeviceAuthorizationRequestContext.addScopes()

Appends scopes to the `scope` parameter.

## Definition

```ts
function addScopes(...scopes: string[]): void;
```

### Parameters

- `scopes`

## Example

```ts
context.addScopes("profile", "email");
context.addScopes("admin");
```

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ function constructor(): this;
- [`OAuth2RequestContext.authenticateWithRequestBody()`](/reference/main/OAuth2RequestContext/authenticateWithRequestBody)
- [`OAuth2RequestContext.setClientId()`](/reference/main/OAuth2RequestContext/setClientId)

- [`appendScopes()`](/reference/main/DeviceAuthorizationRequestContext/appendScopes)
- [`setScopes()`](/reference/main/DeviceAuthorizationRequestContext/setScopes)
- [`addScopes()`](/reference/main/DeviceAuthorizationRequestContext/addScopes)

## Properties

Expand Down

This file was deleted.

24 changes: 24 additions & 0 deletions docs/pages/reference/main/RefreshRequestContext/addScopes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: "RefreshRequestContext.addScopes()"
---

# RefreshRequestContext.addScopes()

Appends scopes to the `scope` parameter.

## Definition

```ts
function addScopes(...scopes: string[]): void;
```

### Parameters

- `scopes`

## Example

```ts
context.addScopes("profile", "email");
context.addScopes("admin");
```
24 changes: 0 additions & 24 deletions docs/pages/reference/main/RefreshRequestContext/appendScopes.md

This file was deleted.

3 changes: 1 addition & 2 deletions docs/pages/reference/main/RefreshRequestContext/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ function constructor(refreshToken: string): this;
- [`OAuth2RequestContext.authenticateWithRequestBody()`](/reference/main/OAuth2RequestContext/authenticateWithRequestBody)
- [`OAuth2RequestContext.setClientId()`](/reference/main/OAuth2RequestContext/setClientId)

- [`appendScopes()`](/reference/main/RefreshRequestContext/appendScopes)
- [`setScopes()`](/reference/main/RefreshRequestContext/setScopes)
- [`addScopes()`](/reference/main/RefreshRequestContext/addScopes)

## Properties

Expand Down
24 changes: 0 additions & 24 deletions docs/pages/reference/main/RefreshRequestContext/setScopes.md

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@oslojs/oauth2",
"type": "module",
"version": "0.2.0",
"version": "0.3.0",
"description": "A runtime-agnostic OAuth 2.0 library",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
6 changes: 1 addition & 5 deletions src/authorization-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ export class AuthorizationCodeAuthorizationURL extends URL {
this.searchParams.set("redirect_uri", redirectURI);
}

public setScopes(...scopes: string[]): void {
this.searchParams.set("scope", scopes.join(" "));
}

public appendScopes(...scopes: string[]): void {
public addScopes(...scopes: string[]): void {
if (scopes.length < 1) {
return;
}
Expand Down
6 changes: 1 addition & 5 deletions src/device-authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ export class DeviceAuthorizationRequestContext extends OAuth2RequestContext {
super("POST");
}

public setScopes(...scopes: string[]): void {
this.body.set("scope", scopes.join(" "));
}

public appendScopes(...scopes: string[]): void {
public addScopes(...scopes: string[]): void {
if (scopes.length < 1) {
return;
}
Expand Down
6 changes: 1 addition & 5 deletions src/refresh-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ export class RefreshRequestContext extends OAuth2RequestContext {
this.body.set("refresh_token", refreshToken);
}

public setScopes(...scopes: string[]): void {
this.body.set("scope", scopes.join(" "));
}

public appendScopes(...scopes: string[]): void {
public addScopes(...scopes: string[]): void {
if (scopes.length < 1) {
return;
}
Expand Down

0 comments on commit f292061

Please sign in to comment.