Skip to content

Commit

Permalink
refactor(login): support 2FA for non-browser SDKs
Browse files Browse the repository at this point in the history
BREAKING CHANGE: To support 2FA on non-browser (e.g. native mobile) apps we have added the Ory Session Token as a possible parameter to both `initializeSelfServiceLoginFlowWithoutBrowser` and `submitSelfServiceLoginFlow`. Depending on the SDK generator, the order of the arguments may have changed. In JavaScript:

```patch
- .submitSelfServiceLoginFlow(flow.id, payload)
+ .submitSelfServiceLoginFlow(flow.id, sessionToken, payload)
+ // or if the user has no session yet:
+ .submitSelfServiceLoginFlow(flow.id, undefined, payload)
```
  • Loading branch information
aeneasr committed Oct 19, 2021
1 parent 12f98f2 commit df4846d
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 70 deletions.
2 changes: 0 additions & 2 deletions internal/httpclient/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ docs/SubmitSelfServiceVerificationFlowBody.md
docs/SubmitSelfServiceVerificationFlowWithLinkMethodBody.md
docs/SuccessfulSelfServiceLoginWithoutBrowser.md
docs/SuccessfulSelfServiceRegistrationWithoutBrowser.md
docs/SuccessfulSelfServiceSettingsWithoutBrowser.md
docs/UiContainer.md
docs/UiNode.md
docs/UiNodeAnchorAttributes.md
Expand Down Expand Up @@ -188,7 +187,6 @@ model_submit_self_service_verification_flow_body.go
model_submit_self_service_verification_flow_with_link_method_body.go
model_successful_self_service_login_without_browser.go
model_successful_self_service_registration_without_browser.go
model_successful_self_service_settings_without_browser.go
model_ui_container.go
model_ui_node.go
model_ui_node_anchor_attributes.go
Expand Down
1 change: 0 additions & 1 deletion internal/httpclient/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ Class | Method | HTTP request | Description
- [SubmitSelfServiceVerificationFlowWithLinkMethodBody](docs/SubmitSelfServiceVerificationFlowWithLinkMethodBody.md)
- [SuccessfulSelfServiceLoginWithoutBrowser](docs/SuccessfulSelfServiceLoginWithoutBrowser.md)
- [SuccessfulSelfServiceRegistrationWithoutBrowser](docs/SuccessfulSelfServiceRegistrationWithoutBrowser.md)
- [SuccessfulSelfServiceSettingsWithoutBrowser](docs/SuccessfulSelfServiceSettingsWithoutBrowser.md)
- [UiContainer](docs/UiContainer.md)
- [UiNode](docs/UiNode.md)
- [UiNodeAnchorAttributes](docs/UiNodeAnchorAttributes.md)
Expand Down
34 changes: 24 additions & 10 deletions internal/httpclient/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,14 @@ paths:
schema:
type: string
style: form
- description: The Session Token of the Identity performing the settings flow.
explode: false
in: header
name: X-Session-Token
required: false
schema:
type: string
style: simple
requestBody:
content:
application/json:
Expand Down Expand Up @@ -609,6 +617,14 @@ paths:
schema:
type: string
style: form
- description: The Session Token of the Identity performing the settings flow.
explode: false
in: header
name: X-Session-Token
required: false
schema:
type: string
style: simple
responses:
"200":
content:
Expand Down Expand Up @@ -676,6 +692,14 @@ paths:
schema:
type: string
style: form
- description: The Session Token of the Identity performing the settings flow.
explode: false
in: header
name: X-Session-Token
required: false
schema:
type: string
style: simple
responses:
"200":
content:
Expand Down Expand Up @@ -4424,16 +4448,6 @@ components:
required:
- identity
type: object
successfulSelfServiceSettingsWithoutBrowser:
description: The Response for Settings Flows via API
properties:
flow:
$ref: '#/components/schemas/selfServiceSettingsFlow'
identity:
$ref: '#/components/schemas/identity'
required:
- flow
type: object
uiContainer:
description: Container represents a HTML Form. The container can work with both
HTTP Form and JSON requests
Expand Down
40 changes: 32 additions & 8 deletions internal/httpclient/api_v0alpha1.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions internal/httpclient/docs/V0alpha1Api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ No authorization required

## InitializeSelfServiceLoginFlowForBrowsers

> SelfServiceLoginFlow InitializeSelfServiceLoginFlowForBrowsers(ctx).Refresh(refresh).Aal(aal).Execute()
> SelfServiceLoginFlow InitializeSelfServiceLoginFlowForBrowsers(ctx).Refresh(refresh).Aal(aal).XSessionToken(xSessionToken).Execute()
Initialize Login Flow for Browsers

Expand All @@ -1085,10 +1085,11 @@ import (
func main() {
refresh := true // bool | Refresh a login session If set to true, this will refresh an existing login session by asking the user to sign in again. This will reset the authenticated_at time of the session. (optional)
aal := "aal_example" // string | Request a Specific AuthenticationMethod Assurance Level Use this parameter to upgrade an existing session's authenticator assurance level (AAL). This allows you to ask for multi-factor authentication. When an identity sign in using e.g. username+password, the AAL is 1. If you wish to \"upgrade\" the session's security by asking the user to perform TOTP / WebAuth/ ... you would set this to \"aal2\". (optional)
xSessionToken := "xSessionToken_example" // string | The Session Token of the Identity performing the settings flow. (optional)

configuration := openapiclient.NewConfiguration()
apiClient := openapiclient.NewAPIClient(configuration)
resp, r, err := apiClient.V0alpha1Api.InitializeSelfServiceLoginFlowForBrowsers(context.Background()).Refresh(refresh).Aal(aal).Execute()
resp, r, err := apiClient.V0alpha1Api.InitializeSelfServiceLoginFlowForBrowsers(context.Background()).Refresh(refresh).Aal(aal).XSessionToken(xSessionToken).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `V0alpha1Api.InitializeSelfServiceLoginFlowForBrowsers``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
Expand All @@ -1111,6 +1112,7 @@ Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**refresh** | **bool** | Refresh a login session If set to true, this will refresh an existing login session by asking the user to sign in again. This will reset the authenticated_at time of the session. |
**aal** | **string** | Request a Specific AuthenticationMethod Assurance Level Use this parameter to upgrade an existing session's authenticator assurance level (AAL). This allows you to ask for multi-factor authentication. When an identity sign in using e.g. username+password, the AAL is 1. If you wish to \"upgrade\" the session's security by asking the user to perform TOTP / WebAuth/ ... you would set this to \"aal2\". |
**xSessionToken** | **string** | The Session Token of the Identity performing the settings flow. |

### Return type

Expand All @@ -1132,7 +1134,7 @@ No authorization required

## InitializeSelfServiceLoginFlowWithoutBrowser

> SelfServiceLoginFlow InitializeSelfServiceLoginFlowWithoutBrowser(ctx).Refresh(refresh).Aal(aal).Execute()
> SelfServiceLoginFlow InitializeSelfServiceLoginFlowWithoutBrowser(ctx).Refresh(refresh).Aal(aal).XSessionToken(xSessionToken).Execute()
Initialize Login Flow for APIs, Services, Apps, ...

Expand All @@ -1153,10 +1155,11 @@ import (
func main() {
refresh := true // bool | Refresh a login session If set to true, this will refresh an existing login session by asking the user to sign in again. This will reset the authenticated_at time of the session. (optional)
aal := "aal_example" // string | Request a Specific AuthenticationMethod Assurance Level Use this parameter to upgrade an existing session's authenticator assurance level (AAL). This allows you to ask for multi-factor authentication. When an identity sign in using e.g. username+password, the AAL is 1. If you wish to \"upgrade\" the session's security by asking the user to perform TOTP / WebAuth/ ... you would set this to \"aal2\". (optional)
xSessionToken := "xSessionToken_example" // string | The Session Token of the Identity performing the settings flow. (optional)

configuration := openapiclient.NewConfiguration()
apiClient := openapiclient.NewAPIClient(configuration)
resp, r, err := apiClient.V0alpha1Api.InitializeSelfServiceLoginFlowWithoutBrowser(context.Background()).Refresh(refresh).Aal(aal).Execute()
resp, r, err := apiClient.V0alpha1Api.InitializeSelfServiceLoginFlowWithoutBrowser(context.Background()).Refresh(refresh).Aal(aal).XSessionToken(xSessionToken).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `V0alpha1Api.InitializeSelfServiceLoginFlowWithoutBrowser``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
Expand All @@ -1179,6 +1182,7 @@ Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**refresh** | **bool** | Refresh a login session If set to true, this will refresh an existing login session by asking the user to sign in again. This will reset the authenticated_at time of the session. |
**aal** | **string** | Request a Specific AuthenticationMethod Assurance Level Use this parameter to upgrade an existing session's authenticator assurance level (AAL). This allows you to ask for multi-factor authentication. When an identity sign in using e.g. username+password, the AAL is 1. If you wish to \"upgrade\" the session's security by asking the user to perform TOTP / WebAuth/ ... you would set this to \"aal2\". |
**xSessionToken** | **string** | The Session Token of the Identity performing the settings flow. |

### Return type

Expand Down Expand Up @@ -1698,7 +1702,7 @@ No authorization required

## SubmitSelfServiceLoginFlow

> SuccessfulSelfServiceLoginWithoutBrowser SubmitSelfServiceLoginFlow(ctx).Flow(flow).SubmitSelfServiceLoginFlowBody(submitSelfServiceLoginFlowBody).Execute()
> SuccessfulSelfServiceLoginWithoutBrowser SubmitSelfServiceLoginFlow(ctx).Flow(flow).XSessionToken(xSessionToken).SubmitSelfServiceLoginFlowBody(submitSelfServiceLoginFlowBody).Execute()
Submit a Login Flow

Expand All @@ -1718,11 +1722,12 @@ import (

func main() {
flow := "flow_example" // string | The Login Flow ID The value for this parameter comes from `flow` URL Query parameter sent to your application (e.g. `/login?flow=abcde`).
xSessionToken := "xSessionToken_example" // string | The Session Token of the Identity performing the settings flow. (optional)
submitSelfServiceLoginFlowBody := openapiclient.submitSelfServiceLoginFlowBody{SubmitSelfServiceLoginFlowWithOidcMethodBody: openapiclient.NewSubmitSelfServiceLoginFlowWithOidcMethodBody("Method_example", "Traits_example")} // SubmitSelfServiceLoginFlowBody | (optional)

configuration := openapiclient.NewConfiguration()
apiClient := openapiclient.NewAPIClient(configuration)
resp, r, err := apiClient.V0alpha1Api.SubmitSelfServiceLoginFlow(context.Background()).Flow(flow).SubmitSelfServiceLoginFlowBody(submitSelfServiceLoginFlowBody).Execute()
resp, r, err := apiClient.V0alpha1Api.SubmitSelfServiceLoginFlow(context.Background()).Flow(flow).XSessionToken(xSessionToken).SubmitSelfServiceLoginFlowBody(submitSelfServiceLoginFlowBody).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `V0alpha1Api.SubmitSelfServiceLoginFlow``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
Expand All @@ -1744,6 +1749,7 @@ Other parameters are passed through a pointer to a apiSubmitSelfServiceLoginFlow
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**flow** | **string** | The Login Flow ID The value for this parameter comes from `flow` URL Query parameter sent to your application (e.g. `/login?flow=abcde`). |
**xSessionToken** | **string** | The Session Token of the Identity performing the settings flow. |
**submitSelfServiceLoginFlowBody** | [**SubmitSelfServiceLoginFlowBody**](SubmitSelfServiceLoginFlowBody.md) | |

### Return type
Expand Down
10 changes: 10 additions & 0 deletions selfservice/flow/login/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ type initializeSelfServiceLoginFlowWithoutBrowser struct {
//
// in: query
RequestAAL identity.AuthenticatorAssuranceLevel `json:"aal"`

// The Session Token of the Identity performing the settings flow.
//
// in: header
SessionToken string `json:"X-Session-Token"`
}

// swagger:route GET /self-service/login/api v0alpha1 initializeSelfServiceLoginFlowWithoutBrowser
Expand Down Expand Up @@ -394,6 +399,11 @@ type submitSelfServiceLoginFlow struct {

// in: body
Body submitSelfServiceLoginFlowBody

// The Session Token of the Identity performing the settings flow.
//
// in: header
SessionToken string `json:"X-Session-Token"`
}

// swagger:model submitSelfServiceLoginFlowBody
Expand Down
39 changes: 24 additions & 15 deletions spec/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -2105,21 +2105,6 @@
],
"type": "object"
},
"successfulSelfServiceSettingsWithoutBrowser": {
"description": "The Response for Settings Flows via API",
"properties": {
"flow": {
"$ref": "#/components/schemas/selfServiceSettingsFlow"
},
"identity": {
"$ref": "#/components/schemas/identity"
}
},
"required": [
"flow"
],
"type": "object"
},
"uiContainer": {
"description": "Container represents a HTML Form. The container can work with both HTTP Form and JSON requests",
"properties": {
Expand Down Expand Up @@ -3110,6 +3095,14 @@
"schema": {
"type": "string"
}
},
{
"description": "The Session Token of the Identity performing the settings flow.",
"in": "header",
"name": "X-Session-Token",
"schema": {
"type": "string"
}
}
],
"requestBody": {
Expand Down Expand Up @@ -3188,6 +3181,14 @@
"schema": {
"type": "string"
}
},
{
"description": "The Session Token of the Identity performing the settings flow.",
"in": "header",
"name": "X-Session-Token",
"schema": {
"type": "string"
}
}
],
"responses": {
Expand Down Expand Up @@ -3248,6 +3249,14 @@
"schema": {
"type": "string"
}
},
{
"description": "The Session Token of the Identity performing the settings flow.",
"in": "header",
"name": "X-Session-Token",
"schema": {
"type": "string"
}
}
],
"responses": {
Expand Down

0 comments on commit df4846d

Please sign in to comment.