Skip to content

Latest commit

 

History

History
267 lines (201 loc) · 19.4 KB

File metadata and controls

267 lines (201 loc) · 19.4 KB

DeviceFlow

Overview

Available Operations

authorization

This API parses request parameters of a device authorization request and returns necessary data for the authorization server implementation to process the device authorization request further.

Example Usage

import { Authlete } from "@authlete/typescript-sdk";

const authlete = new Authlete({
  bearer: process.env["AUTHLETE_BEARER"] ?? "",
});

async function run() {
  const result = await authlete.deviceFlow.authorization({
    serviceId: "<id>",
    deviceAuthorizationRequest: {
      parameters: "client_id=26888344961664&scope=history.read",
      clientId: "26888344961664",
      clientSecret: "SfnYOLkJdofrb_66mTd6q03_SDoDEUnpXtvqFaE4k6L6UcpZzbdVJi2GpBj48AvGeDDllwsTruC62WYqQ_LGog",
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { AuthleteCore } from "@authlete/typescript-sdk/core.js";
import { deviceFlowAuthorization } from "@authlete/typescript-sdk/funcs/deviceFlowAuthorization.js";

// Use `AuthleteCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const authlete = new AuthleteCore({
  bearer: process.env["AUTHLETE_BEARER"] ?? "",
});

async function run() {
  const res = await deviceFlowAuthorization(authlete, {
    serviceId: "<id>",
    deviceAuthorizationRequest: {
      parameters: "client_id=26888344961664&scope=history.read",
      clientId: "26888344961664",
      clientSecret: "SfnYOLkJdofrb_66mTd6q03_SDoDEUnpXtvqFaE4k6L6UcpZzbdVJi2GpBj48AvGeDDllwsTruC62WYqQ_LGog",
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("deviceFlowAuthorization failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.DeviceAuthorizationApiRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<models.DeviceAuthorizationResponse>

Errors

Error Type Status Code Content Type
errors.ResultError 400, 401, 403 application/json
errors.ResultError 500 application/json
errors.AuthleteDefaultError 4XX, 5XX */*

verification

The API returns information associated with a user code.

Example Usage

import { Authlete } from "@authlete/typescript-sdk";

const authlete = new Authlete({
  bearer: process.env["AUTHLETE_BEARER"] ?? "",
});

async function run() {
  const result = await authlete.deviceFlow.verification({
    serviceId: "<id>",
    deviceVerificationRequest: {
      userCode: "XWWKPBWVXQ",
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { AuthleteCore } from "@authlete/typescript-sdk/core.js";
import { deviceFlowVerification } from "@authlete/typescript-sdk/funcs/deviceFlowVerification.js";

// Use `AuthleteCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const authlete = new AuthleteCore({
  bearer: process.env["AUTHLETE_BEARER"] ?? "",
});

async function run() {
  const res = await deviceFlowVerification(authlete, {
    serviceId: "<id>",
    deviceVerificationRequest: {
      userCode: "XWWKPBWVXQ",
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("deviceFlowVerification failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.DeviceVerificationApiRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<models.DeviceVerificationResponse>

Errors

Error Type Status Code Content Type
errors.ResultError 400, 401, 403 application/json
errors.ResultError 500 application/json
errors.AuthleteDefaultError 4XX, 5XX */*

complete

This API returns information about what action the authorization server should take after it receives the result of end-user's decision about whether the end-user has approved or rejected a client application's request.

Example Usage

import { Authlete } from "@authlete/typescript-sdk";

const authlete = new Authlete({
  bearer: process.env["AUTHLETE_BEARER"] ?? "",
});

async function run() {
  const result = await authlete.deviceFlow.complete({
    serviceId: "<id>",
    deviceCompleteRequest: {
      userCode: "XWWKPBWVXQ",
      result: "AUTHORIZED",
      subject: "john",
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { AuthleteCore } from "@authlete/typescript-sdk/core.js";
import { deviceFlowComplete } from "@authlete/typescript-sdk/funcs/deviceFlowComplete.js";

// Use `AuthleteCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const authlete = new AuthleteCore({
  bearer: process.env["AUTHLETE_BEARER"] ?? "",
});

async function run() {
  const res = await deviceFlowComplete(authlete, {
    serviceId: "<id>",
    deviceCompleteRequest: {
      userCode: "XWWKPBWVXQ",
      result: "AUTHORIZED",
      subject: "john",
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("deviceFlowComplete failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.DeviceCompleteApiRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<models.DeviceCompleteResponse>

Errors

Error Type Status Code Content Type
errors.ResultError 400, 401, 403 application/json
errors.ResultError 500 application/json
errors.AuthleteDefaultError 4XX, 5XX */*