Skip to main content

Accessing Protected APIs

Cloud has the newest features. Some may not be in a release yet; the newest release is Identity & Access Management 7.3.0.

When building applications with Choreo Identity & Access Management, you'll often need to call protected APIs that require authentication. This guide shows you how to make authenticated HTTP requests using the Choreo Identity & Access Management Vue SDK.

Accessing Protected APIs​

1. Using SDK Built-in HTTP Client​

When your application is wrapped with ``, you can use the useThunderID composable to access the authenticated http module. This module has the following features: - Includes the necessary authentication headers (Bearer token) - Handles token refresh when tokens expire - Provides methods like request() and requestAll() for making API calls Accessing the HTTP Client You can access the http client in two ways: 1. Inside a component: Use the useThunderID composable to get the http instance

const { http } = useThunderID()

2. Using a GraphQL Client​

If you are not using webWorker as the storage type, use the getAccessToken function to fetch the access token. Then manually attach the token to the GraphQL client's authentication headers. Storage Type Limitation This approach is not available when the storage type is set to webWorker. The SDK automatically manages the access token and does not expose it to the main thread. The following example shows how to configure a GraphQL client with authentication using the access token:

src/graphql/client.ts

export function createAuthenticatedClient(accessToken: string) {
const httpLink = createHttpLink({
uri: 'https://api.identity-platform.us.cloud.wso2.com/graphql',
})

const authLink = setContext((_, { headers }) => ({
headers: {
...headers,
authorization: accessToken ? `Bearer ${accessToken}` : '',
},
}))

return new ApolloClient({
link: authLink.concat(httpLink),
cache: new InMemoryCache(),
})
}

Was this page helpful?