-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MLPAB-1739 Add supporter start page and login (#970)
- Loading branch information
Showing
21 changed files
with
1,390 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
describe('Start', () => { | ||
beforeEach(() => { | ||
cy.visit('/supporter-start'); | ||
}); | ||
|
||
it('can be started', () => { | ||
cy.contains("Help someone to make a lasting power of attorney"); | ||
cy.contains('a', 'Start').click(); | ||
|
||
if (Cypress.config().baseUrl.includes('localhost')) { | ||
cy.url().should('contain', '/authorize') | ||
} else { | ||
cy.origin('https://signin.integration.account.gov.uk', () => { | ||
cy.url().should('contain', '/') | ||
}) | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package supporter | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/ministryofjustice/opg-modernising-lpa/internal/onelogin" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/page" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/sesh" | ||
) | ||
|
||
type LoginCallbackOneLoginClient interface { | ||
Exchange(ctx context.Context, code, nonce string) (idToken, accessToken string, err error) | ||
UserInfo(ctx context.Context, accessToken string) (onelogin.UserInfo, error) | ||
} | ||
|
||
func LoginCallback(oneLoginClient LoginCallbackOneLoginClient, sessionStore sesh.Store) page.Handler { | ||
return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { | ||
oneLoginSession, err := sesh.OneLogin(sessionStore, r) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
idToken, accessToken, err := oneLoginClient.Exchange(r.Context(), r.FormValue("code"), oneLoginSession.Nonce) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
userInfo, err := oneLoginClient.UserInfo(r.Context(), accessToken) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := sesh.SetLoginSession(sessionStore, r, w, &sesh.LoginSession{ | ||
IDToken: idToken, | ||
Sub: userInfo.Sub, | ||
Email: userInfo.Email, | ||
}); err != nil { | ||
return err | ||
} | ||
|
||
return page.Paths.Supporter.YourOrganisation.Redirect(w, r, appData) | ||
} | ||
} |
Oops, something went wrong.