Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Identity] [localhost to cloud proposal] @azure/identity-spa #21028

Closed
wants to merge 14 commits into from

Conversation

sadasant
Copy link
Contributor

@sadasant sadasant commented Mar 24, 2022

This package is a WORK IN PROGRESS.

This PR introduces two credentials: RedirectCredential and PopupCredential through a new package, @azure/identity-spa. This effort aims to simplify the development of web backend applications, from localhost to the Azure cloud.

Before I make the actual proposal, I’ll use this draft PR to ask for feedback, and to build the package for the Playwright-based champion scenarios that I’m making.

Fixes #21050

If you want to try out how the new design looks in comparison to the old design, I’m working on mocked tests here:

@sadasant sadasant self-assigned this Mar 24, 2022
@ghost ghost added the Azure.Identity label Mar 24, 2022
@check-enforcer
Copy link

This pull request is protected by Check Enforcer.

What is Check Enforcer?

Check Enforcer helps ensure all pull requests are covered by at least one check-run (typically an Azure Pipeline). When all check-runs associated with this pull request pass then Check Enforcer itself will pass.

Why am I getting this message?

You are getting this message because Check Enforcer did not detect any check-runs being associated with this pull request within five minutes. This may indicate that your pull request is not covered by any pipelines and so Check Enforcer is correctly blocking the pull request being merged.

What should I do now?

If the check-enforcer check-run is not passing and all other check-runs associated with this PR are passing (excluding license-cla) then you could try telling Check Enforcer to evaluate your pull request again. You can do this by adding a comment to this pull request as follows:
/check-enforcer evaluate
Typically evaulation only takes a few seconds. If you know that your pull request is not covered by a pipeline and this is expected you can override Check Enforcer using the following command:
/check-enforcer override
Note that using the override command triggers alerts so that follow-up investigations can occur (PRs still need to be approved as normal).

What if I am onboarding a new service?

Often, new services do not have validation pipelines associated with them, in order to bootstrap pipelines for a new service, you can issue the following command as a pull request comment:
/azp run prepare-pipelines
This will run a pipeline that analyzes the source tree and creates the pipelines necessary to build and validate your pull request. Once the pipeline has been created you can trigger the pipeline using the following comment:
/azp run js - [service] - ci

const pageLoadResult = await credential.onPageLoad();
if (pageLoadResult) {
state = JSON.parse(pageLoadResult.state);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

State and pageLoadResult need to move up.

// A browser application can keep track of its own state and resume after authenticating.
let state = {
application: "state"
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

State might not be useful in popup mode.

// Interactive authentication will happen via a popup window that will appear when the authenticate() method is called.
await credential.authenticate(scopes, {
// The authenticate() method supports sending the browser application state.
state: JSON.stringify(state)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

State might not be useful in popup mode.

code: hash.get("code") || undefined,
state: hash.get("state") || undefined,
};
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn’t useful for the PopupCredential, but it is useful for the RedirectCredential.

*/
async authenticate(
scopes: string | string[],
options: GetTokenOptions = {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options here should include a state property.

): Promise<AuthenticationRecord | undefined> {
return trace(`${this.constructor.name}.authenticate`, options, async (newOptions) => {
const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];
await this.msalFlow.getToken(arrayScopes, newOptions);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MSAL flow should pass the state property to MSAL.


// On page load, developers can retrieve the state of the previous authentication.
const pageLoadResult = await credential.onPageLoad();
if (pageLoadResult) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (pageLoadResult) {
if (pageLoadResult.state) {
Suggested change
if (pageLoadResult) {
if (pageLoadResult) {

@azure-sdk
Copy link
Collaborator

API change check for @azure/core-client

API changes have been detected in @azure/core-client. You can review API changes here

API changes

+     readonly scopes?: string[];

@@ -321,6 +321,7 @@ export interface SerializerOptions {
export class ServiceClient {
constructor(options?: ServiceClientOptions);
readonly pipeline: Pipeline;
readonly scopes?: string[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The authenticate method requires user to pass in the scope

  • this is a way for the user to retrieve the scope from the client.


// @public
export interface SPACredentialOptions extends InteractiveCredentialOptions, CredentialPersistenceOptions {
clientId?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CredentialPersistenceOptions not needed, since the persistence is already done by the MSAL browser

@ghost ghost added the no-recent-activity There has been no recent activity on this issue. label Jul 1, 2022
@ghost
Copy link

ghost commented Jul 1, 2022

Hi @sadasant. Thank you for your interest in helping to improve the Azure SDK experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days.

@KarishmaGhiya
Copy link
Contributor

Please leave this PR open. Don't close Pleaseee

@ghost ghost removed the no-recent-activity There has been no recent activity on this issue. label Jul 2, 2022
@ghost ghost added the no-recent-activity There has been no recent activity on this issue. label Sep 2, 2022
@ghost
Copy link

ghost commented Sep 2, 2022

Hi @sadasant. Thank you for your interest in helping to improve the Azure SDK experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days.

@ghost ghost closed this Sep 9, 2022
@ghost
Copy link

ghost commented Sep 9, 2022

Hi @sadasant. Thank you for your contribution. Since there hasn't been recent engagement, we're going to close this out. Feel free to respond with a comment containing "/reopen" if you'd like to continue working on these changes. Please be sure to use the command to reopen or remove the "no-recent-activity" label; otherwise, this is likely to be closed again with the next cleanup pass.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure.Identity no-recent-activity There has been no recent activity on this issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Identity] [Localhost to cloud] New browser credentials
3 participants