Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit38d3d06

Browse files
committed
feat: add best effort attempt to revoke oauth access token in provider
1 parenta511812 commit38d3d06

File tree

7 files changed

+30
-8
lines changed

7 files changed

+30
-8
lines changed

‎coderd/apidoc/docs.go‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/apidoc/swagger.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/externalauth.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ func (api *API) externalAuthByID(w http.ResponseWriter, r *http.Request) {
8585
// @ID delete-external-auth-user-link-by-id
8686
// @Security CoderSessionToken
8787
// @Tags Git
88-
// @Success 200
88+
// @Produce json
8989
// @Param externalauth path string true "Git Provider ID" format(string)
90+
// @Success 200
9091
// @Router /external-auth/{externalauth} [delete]
9192
func (api*API)deleteExternalAuthByID(w http.ResponseWriter,r*http.Request) {
9293
config:=httpmw.ExternalAuthParam(r)
@@ -128,11 +129,11 @@ func (api *API) deleteExternalAuthByID(w http.ResponseWriter, r *http.Request) {
128129

129130
ok,err:=config.RevokeToken(ctx,link)
130131
iferr!=nil||!ok {
131-
httpapi.Write(ctx,w,http.StatusOK,"Successfully deleted external auth link, access token has NOT been revoked from the oauth2 provider.")
132+
httpapi.Write(ctx,w,http.StatusOK,codersdk.DeleteExternalAuthByIDResponse{TokenRevocationSuccessful:false})
132133
return
133134
}
134135

135-
httpapi.Write(ctx,w,http.StatusOK,"Successfully deleted external auth link and revoked token from the oauth2 provider")
136+
httpapi.Write(ctx,w,http.StatusOK,codersdk.DeleteExternalAuthByIDResponse{TokenRevocationSuccessful:true})
136137
}
137138

138139
// @Summary Post external auth device by ID

‎codersdk/externalauth.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ type ListUserExternalAuthResponse struct {
7373
Links []ExternalAuthLink`json:"links"`
7474
}
7575

76+
typeDeleteExternalAuthByIDResponsestruct {
77+
// TokenRevocationSuccessful set to true if
78+
// token revocation in provider was succesfful
79+
TokenRevocationSuccessfulbool
80+
}
81+
7682
// ExternalAuthLink is a link between a user and an external auth provider.
7783
// It excludes information that requires a token to access, so can be statically
7884
// built from the database and configs.

‎site/src/api/api.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { delay } from "../utils/delay";
2727
import{OneWayWebSocket}from"../utils/OneWayWebSocket";
2828
import{typeFieldError,isApiError}from"./errors";
2929
importtype{
30+
DeleteExternalAuthByIDResponse,
3031
DynamicParametersRequest,
3132
PostWorkspaceUsageRequest,
3233
}from"./typesGenerated";
@@ -1727,7 +1728,9 @@ class ApiMethods {
17271728
returnresp.data;
17281729
};
17291730

1730-
unlinkExternalAuthProvider=async(provider:string):Promise<string>=>{
1731+
unlinkExternalAuthProvider=async(
1732+
provider:string,
1733+
):Promise<DeleteExternalAuthByIDResponse>=>{
17311734
constresp=awaitthis.axios.delete(`/api/v2/external-auth/${provider}`);
17321735
returnresp.data;
17331736
};

‎site/src/api/typesGenerated.ts‎

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎site/src/pages/UserSettingsPage/ExternalAuthPage/ExternalAuthPage.tsx‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ import { useMutation, useQuery, useQueryClient } from "react-query";
1111
import{Section}from"../Section";
1212
import{ExternalAuthPageView}from"./ExternalAuthPageView";
1313

14-
constRevokeMessage="This action will try to revoke the access token from oauth2 provider."
14+
constTryRevokeInfo="This action will try to revoke the access token from oauth2 provider."
1515
+"Auth link will be removed regardlles if token revocation succedess.";
16-
constNoRevokMessage="This action will not revoke the access token from the oauth2 provider."
16+
constNoRevokeInfo="This action will not revoke the access token from the oauth2 provider."
1717
+" It only removes the link on this side. To fully revoke access, you must"
1818
+" do so on the oauth2 provider's side.";
1919

20+
constRevokeSuccess="Successfully deleted external auth link and revoked token from the oauth2 provider."
21+
constRevokeFailed="Successfully deleted external auth link. Token has NOT been revoked from the oauth2 provider."
22+
2023
constExternalAuthPage:FC=()=>{
2124
constqueryClient=useQueryClient();
2225
// This is used to tell the child components something was unlinked and things
@@ -61,7 +64,7 @@ const ExternalAuthPage: FC = () => {
6164
key={appToUnlink}
6265
title="Unlink Application"
6366
verb="Unlinking"
64-
info={appSupportsRevoke ?RevokeMessage :NoRevokMessage}
67+
info={appSupportsRevoke ?TryRevokeInfo :NoRevokeInfo}
6568
label="Name of the application to unlink"
6669
isOpen={appToUnlink!==undefined}
6770
confirmLoading={unlinkAppMutation.isPending}
@@ -78,7 +81,7 @@ const ExternalAuthPage: FC = () => {
7881
// this tells our child components to refetch their data
7982
// as at least 1 provider was unlinked.
8083
setUnlinked(unlinked+1);
81-
displaySuccess(unlinkResp);
84+
displaySuccess(unlinkResp.TokenRevocationSuccessful ?RevokeSuccess :RevokeFailed);
8285
}catch(e){
8386
displayError(getErrorMessage(e,"Error unlinking application."));
8487
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp