# Oauth2 Authorization

**Production Env**

[https://](https://me.nuvosphere.io/)[api.nuvosphere.io](http://api.xx.nuvosphere.io/)

**Staging Env**

[https://api.staging.nuvosphere.io](https://me.staging.nuvosphere.io/)

**Step1 - Initiate authorization**

Request for log in

```
`${host}/#/oauth2-login?switch_account=${switchAccount}&app_id=${appId}&return_url=${encodeURIComponent(returnUrl)}`
```

description

```markup
switch_account:  switch user account
app_id        :  Nuvo middleware app id
return_url    :  Nuvo middleware Authorized Domains
```

**Step2 - Receive authorized code**

After initiating authorization, Nuvo will return\_url and code

```
https://demo.dapp.com/callback?code=xxxxxxx
```

The developer will receive url(<https://demo.dapp.com/callback>), keep the code for the access token use

**Step3 - Request Access Token**

## Request access token

<mark style="color:blue;">`GET`</mark> `/api/v1/oauth2/access_token`

**Query String:** ?appid={appid}\&code={code}

code: the code kept from step2

appid: app id that can be acquired from Nuvo One

#### Request Body

| Name                                    | Type   | Description              |
| --------------------------------------- | ------ | ------------------------ |
| code<mark style="color:red;">\*</mark>  | String | the code kept from step2 |
| appid<mark style="color:red;">\*</mark> | String | Nuvo middleware app id   |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    "code": 200,
    "data": {
        "accessToken": "a7f4216020364aa79d77e18d4965cf2f",　//authorized token，use this token to access related api
        "appId": "60ed992bb520d95b454c4e88",
        "expiresIn": 43200, //valid for 12 hours
        "refreshToken": "aab3accb1180410fbe9341fd0db95d94",　//Refresh time 30 days
        "wcSession": null
    },
    "msg": ""
}
```

{% endtab %}
{% endtabs %}
