<@U04UQ68083H> how can I use go SDK to create new ...
# ory-copilot
w
@chilly-king-10285 how can I use go SDK to create new project within the workspace?
c
A message from kapa.ai
To create a new project within a workspace using the Go SDK, you need to make a POST request to the
/projects
endpoint. The request body should include the details of the project to be created. Here is an example of the request body:
Copy code
json {   'content': {     'application/json': {       'schema': {         'description': 'Create Project Request Body',         'properties': {           'environment': {             'description': 'The environment of the project.\nprod Production\nstage Staging\ndev Development',             'enum': ['prod', 'stage', 'dev'],             'type': 'string',             'x-go-enum-desc': 'prod Production\nstage Staging\ndev Development'           },           'home_region': {             'description': 'Home Region\n\nThe home region of the project. This is the region where the project will be created.\neu-central EUCentral\nus-east USEast\nus-west USWest\nglobal Global',             'enum': ['eu-central', 'us-east', 'us-west', 'global'],             'type': 'string',             'x-go-enum-desc': 'eu-central EUCentral\nus-east USEast\nus-west USWest\nglobal Global'           },           'name': {             'description': 'The name of the project to be created',             'type': 'string'           },           'workspace_id': {             'description': 'The workspace to create the project in.',             'format': 'uuid',             'type': 'string'           }         },         'required': ['name', 'environment'],         'type': 'object'       }     }   },   'x-originalParamName': 'Body' }
The
environment
and
name
fields are required. The
environment
field can be one of
prod
,
stage
, or
dev
. The
home_region
field can be one of
eu-central
,
us-east
,
us-west
, or
global
. To perform this operation, you must be authenticated by means of the
oryWorkspaceApiKey
method. For more details, please refer to the [Ory API Reference](https://www.ory.sh/docs/reference/api). Please note that the actual Go code to make this API request is not provided in the knowledge sources. You would typically use an HTTP client library in Go to make this request.
w
@chilly-king-10285 what's the best practice to refresh JWT tokens using ory frontend client?
c
A message from kapa.ai
Refreshing JWT tokens using Ory involves using the refresh token that was issued during the initial token issuance. When a client refreshes an access token, the old access token becomes invalid, and only the new token is valid. The client can continue accessing the protected resource with the new access token. Here's an example of how to refresh an access token with Ory:
Copy code
javascript // Set up the endpoint and refresh token   const endpoint = "<https://oauth2.example.com/token>"   const refreshToken = "<refresh token>"   const clientId = "<client id>"   const clientSecret = "<client secret>"      const params = new URLSearchParams({     grant_type: "refresh_token",     refresh_token: refreshToken,     scope: "scope1 scope2",     client_id: clientId,     client_secret: clientSecret,   })   // Send a POST request to refresh the access token   fetch(endpoint, {     method: "POST",     headers: {       "Content-Type": "application/x-www-form-urlencoded",     },     body: params.toString(),   })     .then((response) => {       if (!response.ok) {         throw new Error("Failed to refresh access token")       }       return response.json()     })     .then((data) => {       console.log("New access token:", data.access_token)       console.log("New ID token:", data.id_token)       console.log("New refresh token:", data.refresh_token)     })     .catch((error) => {       console.error(error)     })
When a client uses a refresh token to obtain a new access token, the authorization server may also issue a new ID token if the original token exchange included an ID token. The new ID token has an updated expiry time but retains the same
auth_time
(time when the user authenticated). The
auth_time
claim in the ID token is used to determine if the user's authentication session is still active. For more details, please refer to the [Ory OAuth2 refresh token grant documentation](https://www.ory.sh/docs/oauth2-oidc/refresh-token-grant#refreshing-an-access-token).