@microsoft/useragent-sdk
Version:
SDK for building decentralized identity wallets and enterprise agents.
83 lines (82 loc) • 3.31 kB
TypeScript
import Identifier from '../Identifier';
import IResolver from '../resolvers/IResolver';
import OIDCAuthenticationRequest from '../crypto/protocols/did/requests/OIDCAuthenticationRequest';
import OIDCAuthenticationResponse from '../crypto/protocols/did/responses/OIDCAuthenticationResponse';
import IManifest from './oidc/requests/IManifest';
import IRequestPrompt, { IPermissionRequestPrompt } from './oidc/requests/IRequestPrompt';
import { IScopeRequest } from './oidc/requests/IScopeDefinition';
/**
* OIDC optional parameters
*/
export interface OIDCRequestOptions {
/**
* claims to request be included in the response
* Should follow https://openid.net/specs/openid-connect-core-1_0.html#ClaimsParameter
* @throws Claims are a future feature and not yet supported by the user agent.
*/
claimRequests?: {
[claimName: string]: any;
};
/**
* State to include in the response
*/
state?: string;
/**
* Requester manifest for UI presentation
*/
manifest?: IManifest;
/**
* Additional URLs of @see IScopeDefinition to include
*/
scopes?: IScopeRequest[];
}
/**
* Class for creating a User Agent Session for sending and verifying
* Authentication Requests and Responses.
*/
export default class UserAgentSession {
private sender;
private resolver;
private keyReference;
private options;
private cryptoFactory;
private permissions;
constructor(sender: Identifier, keyReference: string, resolver: IResolver);
/**
* Sign a User Agent Request.
* @param redirectUrl url that recipient should send response back to.
* @param nonce nonce that will come back in response.
* @param options Open ID Connect optional parameters
*/
signRequest(redirectUrl: string, nonce: string, options?: OIDCRequestOptions): Promise<string>;
/**
* Send an Open ID Connect User Agent Response.
* @param request Open ID Connect request to respond to.
* @param claims Future Feature: any claims the request asked for.
* @param grants any permissionGrants approved by the user.
* @throws Throws if claims are included
*/
sendResponse(request: OIDCAuthenticationRequest, grants?: IPermissionRequestPrompt[], claims?: any): Promise<any>;
/**
* Verify a request was signed and sent by Identifier.
* @param jws Signed Payload
*/
verify(jws: string): Promise<any>;
/**
* Verify an Open ID Connect response was signed and sent by response.did.
* @param responseJws Signed response token
*/
verifyResponse(responseJws: string): Promise<OIDCAuthenticationResponse>;
/**
* Verify an Open ID Connect request was signed and sent by Identifier, and return all contents
* @param request Signed request token
*/
verifyAndHydrateRequest(requestJws: string): Promise<IRequestPrompt>;
/**
* Parses a encoded scope value and constructs IPermissionRequestPrompts
* @param requester the DID of the requester for this permission
* @param encodedScope The Encoded scope value
* @returns IPermissionRequestPrompt(s) corresponding to the scopes requested
*/
private parseScopeValue;
}